Perform Additional Data Operations in Microsoft Dynamics CRM 2011 Using the REST Endpoint


Applies To: Dynamics CRM 2011

In addition to basic data operations, you can use the REST endpoint for Microsoft Dynamics CRM 2011 to perform some more specialized data operations.

In order to set Microsoft Dynamics CRM Complex Types to null, you must explicitly set each primitive type within them to null.

For example, to set an EntityReference type to null, you must set the Id, the LogicalName, and the Name properties to null. The same is true for OptionSetValue, Money, and BooleanManagedProperty.

Deep insert is a technique in which you can create multiple new related records in the same operation.

 The following sample shows JScript code that uses jQuery to define an account and two related tasks. For more information, see Using jQuery. When the tasks are assigned to the Account_Tasks property representing related tasks and submitted by using a POST request to the /AccountSet URI, the account and the two related tasks are created in a single operation:

var account = new Object();
account.Name = "Sample Account";

var task1 = new Object();
task1.Subject = "Sample Task 1";

var task2 = new Object();
task2.Subject = "Sample Task 2";

var tasks = new Array();

account.Account_Tasks = tasks;

var jsonAccount = window.JSON.stringify(account);

$.ajax({ type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: ODataPath + "/AccountSet",
    data: jsonAccount,
    beforeSend: function (XMLHttpRequest) {
        //Specifying this header ensures that the results will be returned as JSON.
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    success: function (data, textStatus, XmlHttpRequest) {},
    error: function (XMLHttpRequest, textStatus, errorThrown) {}

Deep insert works from either side of an entity relationship. The previous example created new tasks in the context of a new account record. You can reverse this to create a new account record in the context of creating a new related task by submitting a POST request to the /TaskSet URI.

You can update individual attribute values for a record by using a HTTP PUT request using a URI that addresses a specific attribute and passing the new value in the body of the request.


Using this URI in an HTTP PUT request with a new name for the account in the body will update the value of only that property.

There are two ways to associate or disassociate records: by updating the data in the entity reference properties just as if they were any other type of property or through the URL of the link resource.

When associating or disassociating records on the many side of an N:1 entity relationship, use the $links URI. For N:N and 1:N entity relationships use the URI without $links.

The following sample shows that the URI will return a URI for any opportunity records associated with the account record specified in the URI:


If you want to associate an existing opportunity record with this account, you must use this URI in a HTTP POST request that includes the URI for that opportunity in the body.


When associating a record on the many side of a N:1 entity relationship, any existing value will be overwritten when the reference only supports a single value.

Similarly, to disassociate an opportunity, you must use an HTTP DELETE request that includes a reference to a specific link resource. The following sample shows that the URI represents a specific account record associated to another account by using ParentAccountId entity reference property:


A HTTP DELETE request against this URI will remove the association.


Some entity relationships are required. You will get an error if you attempt to delete data for a required relationship.

Microsoft Dynamics CRM 2011

© Microsoft Corporation. All rights reserved. Copyright