0
votes

Is there any example how to call AddListMembersList? I tried with:

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);

but I get error:

"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()"

Any advice?

2

2 Answers

1
votes

Exact answer can be found here: http://butenko.pro/2018/03/01/how-to-add-records-to-marketing-list-using-webapi/

From link adjusted to my example:

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);
1
votes

You are trying to call an action - AddListMembersList. Syntax would be like:

/api/data/v8.2/AddListMembersList

I would recommend you to use CRMRestBuilder to play around, test & understand.

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));