title: How to update or delete Sender and Receiver of an existing phonecall / email record using MS Dynamics CRM REST Endpoint
body: <p>I am working on the application where I need to create and later update phonecall / email records in MS Dynamics CRM 2011 using REST API. Using Soap API is not an option.</p>
  
  <p>I have figured out how to create the phonecall / email record (which is well documented <a href="http://mscrmshop.blogspot.ca/2011/09/how-to-create-email-activity-using-rest.html" rel="nofollow">here</a>
  or <a href="http://community.dynamics.com/product/crm/crmtechnical/b/crmcustomereffective/archive/2011/12/06/using-the-crm-2011-rest-services-and-deep-insert-to-create-activities.aspx" rel="nofollow">here</a>).</p>
  
  <p>Updating the existing phonecall / email record itself is not a problem either. </p>
  
  <p>My question is: HOW do I update the Receiver and Sender fields (To and From) of an existing phonecall / email record?</p>
  
  <p>I have tried different approaches described below with no luck so far.</p>
  
  <p>I get <code>Error processing request stream. Deep updates are not supported in PUT operations.</code> error if I try to update phonecall_activity_parties relationship - see code below</p>
  
  <pre><code>var callLogEntity = { 
      "Subject": "My call", "Description": "Call comments go here" };
  
  var activityParties = [];
  activityParties.push({
      "PartyId": {"Id":"4A9FD17D-5890-4BF0-94AA-D68285C46039", "LogicalName":"contact"},
      "ParticipationTypeMask": { "Value": 1 }
  }); // sender is a contact
  activityParties.push({
      "PartyId": { "Id": Xrm.Page.context.getUserId(), "LogicalName": "systemuser" },
      "ParticipationTypeMask": { "Value": 2 }
  }); // receiver is a current user
  callLogEntity.phonecall_activity_parties = activityParties;
  
  var restQueryUrl = "http://&lt;crm_url&gt;/XRMServices/2011/OrganizationData.svc/" +
      "PhoneCallSet(guid'" + callLogId + "')";
  $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      datatype: "json",
      data: JSON.stringify(callLogEntity),
      url: restQueryUrl,
      beforeSend: function (XMLHttpRequest)
      {
          XMLHttpRequest.setRequestHeader("Accept", "application/json");
          XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
      },
      success: function (data, textStatus, XmlHttpRequest)
      {
          console.log("Success");
      },
      error: function (XmlHttpRequest, textStatus, errorObject)
      {
          console.warn("Request FAILED: " + XmlHttpRequest.responseText);
      }
  });
  </code></pre>
  
  <p>I get <code>An activityparty cannot be disassociated from an activity</code> error if I try to disassociate an activity using the disassociateRecords method from <a href="http://technet.microsoft.com/en-us/library/hh372956.aspx" rel="nofollow">this SDK Example</a> - see code below</p>
  
  <pre><code>var restQueryUrl = "http://&lt;crm_url&gt;/XRMServices/2011/OrganizationData.svc/" +
      "PhoneCallSet(guid'" + callLogId + "')/$links/" +
      "phonecall_activity_parties(guid'" + activityPartyId + "')";
  $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: restQueryUrl,
      beforeSend: function (XMLHttpRequest)
      {
          XMLHttpRequest.setRequestHeader("Accept", "application/json");
          XMLHttpRequest.setRequestHeader("X-HTTP-Method", "DELETE");
      },
      success: function (data, textStatus, XmlHttpRequest)
      {
          console.log("Success");
      },
      error: function (XmlHttpRequest, textStatus, errorObject)
      {
          console.warn("Request FAILED: " + XmlHttpRequest.responseText);
      }
  });
  </code></pre>
  
  <p>I get <code>Forbidden</code> error when I try to delete one of the ActivityParty found in the phonecall_activity_parties directly from ActivityPartySet.</p>
  
  <pre><code>var restQueryUrl = "http://&lt;crm_url&gt;/XRMServices/2011/OrganizationData.svc/" +
      "ActivityPartySet(guid'" + activityPartyId + "')";
  // then do an AJAX POST request with "X-HTTP-Method": "DELETE" header
  </code></pre>
  
  <p>Updating each ActivityParty from that list individually has no effect on the phonecall record (i.e. the MERGE request seems to be successful, but the ActivityParty still points to the old record)</p>
  
  <pre><code>var activityData = {
      "PartyId":{"Id":"cc1cdb40-a844-e211-ab1a-000c297d9c06","LogicalName":"contact"},
      "ParticipationTypeMask":{"Value":1}
  };
  var restQueryUrl = "http://&lt;crm_url&gt;/XRMServices/2011/OrganizationData.svc/" +
      "ActivityPartySet(guid'" + activityPartyId + "')";
  // then do an AJAX post request with "X-HTTP-Method": "MERGE" header
  // and activityData as the message body
  </code></pre>
  
  <p>If anyone can shed some light on how to change (or delete, as in "clear the field") the Sender and Receiver of an EXISTING phonecall / email record I would greatly appreciate it.</p>