Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Dynamic CRM endpoints to remove a Contact from a List

I have an Angular App that uses the built in DYNAMIC CRM endpoints, mainly the "/XRMServices/2011/OrganizationData.svc" but also the "/api/data/v8.0" for a few functions, including the call to Add Members to a Marketing List.

This code works perfectly to add a member to a list:

function attachContactToList(memberGuid, listGuid) {
    var data = {
        "EntityId": memberGuid
    };
    var req = new XMLHttpRequest();
    req.open("POST", "<<path to CRM Service>>/api/data/v8.0/lists("+ listGuid + ")/Microsoft.Dynamics.CRM.AddMemberList", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 200) {
                notifier.alert("Added to List.");
            } else {
                raiseError(JSON.parse(this.response).error);
            }
        }
    };
    req.send(JSON.stringify(data));
}

However when I attempt to remove a member from a list using the RemoveMemberList call, it fails. Here is the code for the remove:

function deleteListFromContact(memberGuid, listGuid) {
    var data = {
        "EntityId": memberGuid
    };
    var req = new XMLHttpRequest();
    req.open("POST", "<<path to CRM Service>>/api/data/v8.0/lists(" +  listGuid + ")/Microsoft.Dynamics.CRM.RemoveMemberList", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 200) {
                notifier.alert("Removed from List.");
            } else {
                raiseError(JSON.parse(this.response).error);
            }
        }
    };
    req.send(JSON.stringify(data));
}

The error I am getting is:

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

Any help would be appreciated. This is the only stumbling block in my entire application, once this is corrected.... I am good to go.

Thanks

like image 338
Hoodoo Operator Avatar asked Nov 09 '22 07:11

Hoodoo Operator


1 Answers

The Remove Member List Request is not currently implemented:

https://msdn.microsoft.com/en-us/library/mt628816.aspx

Missing functions and actions for some organization service messages The following table lists the messages that don't have a corresponding function or action after Microsoft Dynamics CRM Online 2016 Update 1 and Microsoft Dynamics CRM 2016 Service Pack 1 are applied.

+------------------------------+-----------------------------------+----------------------------------+
| GrantAccessRequest           | GrantAccessRequest                | ModifyAccessRequest              |
+------------------------------+-----------------------------------+----------------------------------+
| QualifyLeadRequest           | ReactivateEntityKeyRequest        | RemoveMemberListRequest          |
+------------------------------+-----------------------------------+----------------------------------+
| RemoveItemCampaignRequest    | RemoveItemCampaignActivityRequest | RetrieveByResourcesServiceReques |
+------------------------------+-----------------------------------+----------------------------------+
| RetrieveFilteredFormsRequest |                                   |                                  |
+------------------------------+-----------------------------------+----------------------------------+

You'll have to use the "/XRMServices/2011/OrganizationData.svc" or wait until the next release.

like image 69
Daryl Avatar answered Nov 14 '22 21:11

Daryl