Answered by:
Deleting listcontact_association via REST- Endpoint

Question
-
Hello,
I am trying to delete a listcontact_association using REST- Endpoint. I am running a HTTP- DELETE against the following URL:
[...]/XRMServices/2011/OrganizationData.svc/ContactSet(guid'[ContactID]')/listcontact_association(guid'[ListID]')
Hower this Query doesn't delete the listcontact_association for the given Contact - it deletes the whole List instead.
Can anyone tell me how to fix this?
Edit: MS CRM 2011 on premise
- Edited by MultiZap Tuesday, September 30, 2014 8:41 AM
Tuesday, September 30, 2014 8:24 AM
Answers
-
It seems like REST is not fully implemented so i decided to using SOAP instead. Now it works.
Endpoint:
[...]/xrmservices/2011/Organization.svc/web
Headers:
SOAPAction: http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute
Accept: application/xml, text/xml, */*
Content-Type: text/xml; charset=utf-8
<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> <s:Body> <Execute xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'> <request i:type='b:RemoveMemberListRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'> <a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'> <a:KeyValuePairOfstringanyType> <c:key>ListId</c:key> <c:value i:type='d:guid' xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/'>[ListID]</c:value> </a:KeyValuePairOfstringanyType> <a:KeyValuePairOfstringanyType> <c:key>EntityId</c:key> <c:value i:type='d:guid' xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/'>[ContactID]</c:value> </a:KeyValuePairOfstringanyType> </a:Parameters> <a:RequestId i:nil='true' /> <a:RequestName>RemoveMemberList</a:RequestName> </request> </Execute> </s:Body> </s:Envelope>
Tuesday, September 30, 2014 12:44 PM
All replies
-
It seems like the URL points to
[...]/XRMServices/2011/OrganizationData.svc/ListSet(guid'[ListID]')The output of these two querys is exactly the same.
Tuesday, September 30, 2014 8:47 AM -
liscontact_association is a N:N relationship. In this case you need to Disassociate the records, not deleting them.
Here the MSDN article to with a disassociate sample using REST endpoint
http://msdn.microsoft.com/en-us/library/hh372956.aspx
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Tuesday, September 30, 2014 9:13 AM
- Unproposed as answer by MultiZap Tuesday, September 30, 2014 9:42 AM
Tuesday, September 30, 2014 9:12 AM -
liscontact_association is a N:N relationship. In this case you need to Disassociate the records, not deleting them.
Here the MSDN article to with a disassociate sample using REST endpoint
http://msdn.microsoft.com/en-us/library/hh372956.aspx
My blog: www.crmanswers.net - Rockstar 365 Profile
According to this example, two Records will be disassociated by running a HTTP- Post with http-x-method:delete against the URL which is basically a HTTP-DELETE
req.open("POST", encodeURI(this._ODataPath() + parentType + "Set(guid'" + parentId + "')/$links/" + relationshipName + "(guid'" + childId + "')"), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("X-HTTP-Method", "DELETE");
using the $links parameter in my query throws an error:
'Invalid role specified for entity 'contact' in relationship 'listcontact_association.Referencing'
- Edited by MultiZap Tuesday, September 30, 2014 9:34 AM
Tuesday, September 30, 2014 9:26 AM -
try to switch the entities
instead of ContactSet contactId listId
use ListSet listId contactId
My blog: www.crmanswers.net - Rockstar 365 Profile
Tuesday, September 30, 2014 9:44 AM -
I tried this before. My query looks like this
[...]/XRMServices/2011/OrganizationData.svc/ListSet(guid'[ListID]')/listcontact_association(guid'[ContactID]')
and throws this Error:
'Query in RelationshipQuery must be for related entity.'
Tuesday, September 30, 2014 9:54 AM -
It seems like REST is not fully implemented so i decided to using SOAP instead. Now it works.
Endpoint:
[...]/xrmservices/2011/Organization.svc/web
Headers:
SOAPAction: http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute
Accept: application/xml, text/xml, */*
Content-Type: text/xml; charset=utf-8
<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> <s:Body> <Execute xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'> <request i:type='b:RemoveMemberListRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'> <a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'> <a:KeyValuePairOfstringanyType> <c:key>ListId</c:key> <c:value i:type='d:guid' xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/'>[ListID]</c:value> </a:KeyValuePairOfstringanyType> <a:KeyValuePairOfstringanyType> <c:key>EntityId</c:key> <c:value i:type='d:guid' xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/'>[ContactID]</c:value> </a:KeyValuePairOfstringanyType> </a:Parameters> <a:RequestId i:nil='true' /> <a:RequestName>RemoveMemberList</a:RequestName> </request> </Execute> </s:Body> </s:Envelope>
Tuesday, September 30, 2014 12:44 PM