Dynamics CRM 365 WebApi 8.2 AddListMembersList 方法

Dynamics CRM 365 WebApi 8.2 AddListMembersList method

有没有调用AddListMembersList的例子?我试过:

let data = {
       "MemberIds": [500aa55d-f0c2-e711-80ca-005056bb6cde, 500aa55d-f0c2-e711-80ca-005056bb6cd, 500aa55d-f0c2-e711-80ca-005056bb6cde]
};

http.post(this.baseUrl + 'lists(770aa55d-f0c2-e711-80ca-005056bb6cde)/Microsoft.Dynamics.CRM.AddListMembersList', data);

但我收到错误:

"error":{ "code":"","message":"Request message has unresolved parameters.","innererror":{ "message":"Request message has unresolved parameters.","type":"Microsoft.Crm.CrmHttpException","stacktrace":" bei Microsoft.Crm.Extensibility.OData.CrmODataRoutingConvention.SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup`2 actionMap)\r\n bei System.Web.OData.Routing.ODataActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n bei System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n bei System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"

有什么建议吗?

您正在尝试调用一个操作 - AddListMembersList。语法如下:

/api/data/v8.2/AddListMembersList

我建议您使用 CRMRestBuilder 来体验、测试和理解。

var parameters = {};
var list = {};
list.listid = "00000000-0000-0000-0000-000000000000";
list["@odata.type"] = "Microsoft.Dynamics.CRM.list";
parameters.List = list;
var members1 = {};
members1.contactid = "00000000-0000-0000-0000-000000000000";
members1["@odata.type"] = "Microsoft.Dynamics.CRM.contact";
parameters.Members = [members1];

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/AddListMembersList", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 204) {
            //Success - No Return Data - Do Something
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send(JSON.stringify(parameters));

可以在这里找到准确的答案:http://butenko.pro/2018/03/01/how-to-add-records-to-marketing-list-using-webapi/

从link调整到我的例子:

var data = {
    List: {
        listid: "9DEE7D76-611D-E811-A95B-000D3A1087A0",
        "@odata.type": "Microsoft.Dynamics.CRM.list"
    },
    Members: [{
        accountid: "6785A521-A2C0-E711-A950-000D3A109280",
        "@odata.type": "Microsoft.Dynamics.CRM.account"
    },
    {
        accountid: "3653A521-A2C0-E711-A950-000D3A109280",
        "@odata.type": "Microsoft.Dynamics.CRM.account"
    }]
};

this.http.post(this.baseUrl + 'AddListMembersList', data);