MS CRM 2011 REST Service – Obtaining related resources

The operation set returned upon interrogation is large but the internal operation structure does not allow for the retrieval of inter-related items without a change to the GetResourceSet operation (e.g. GetContactSet) for each Parent resource. For example, by default it would not be possible to get the tasks related to a specific contact (e.g. GetContactSet(guid’ … ‘)/Contact_Tasks ).

To see a list of the kinds of related resources available for a parent, write a task which obtains a single parent using its guid. Save the output and inspect the file. There are many entries in the “links” section which show the relationships to other items.

Principles of the solution

To allow for the retrieval of related resources, a copy of the original Get operation could be made and modified. However, it is better to start from a new service which can contain just those operations required. This has editing performance advantages and separates these specific operations for ease of use.

(It is not recommended to combine this and the original (interrogated or imported) CRM 2011 web service otherwise performance during editing will deteriorate.)

Create a new Web Service

In this solution a new web service global connection is created and operations are set up which permit the user to identify the main resource and collect information regarding specific related resources.

It is necessary to know the URL, Username, Password and Domain for the REST service.

You will also have to know the GUID for a Parent Resource. This is best obtained by running the Get operation for the resource set, saving the output and inspecting this for the guid.

Steps

  1. In the TaskCentre system tree expand System -> Tools -> Execute and double-click the Web Service Connector tool to open the global configuration.
  2. Click Add to begin creating a new web service configuration.
  3. Provide a name for the new configuration (e.g. MS CRM 2011 REST RELATIONS).
  4. Select the last option “I do not have a definition…” followed by OK.
  5. Click Web Service Root tab and provide the web service URL.
  6. Click the Authorisation tab and provide any credentials used to access the web service.
  7. Click the Operations tab. Under the Single Message Operations area, click Add to create a new operation.
  8. Provide a name for the operation (e.g. GetContact_Tasks) followed by OK.
  9. Click the URL tab and add a parameter which will be the identifier for the Parent resource (e.g. contactID). You may choose to put in a description for this parameter.
  10. Tick the Use the connection URL check box. In the editing area for the URL add the necessary retrieval details including the parameter. Note that you must have a forward slash at the end of the main URL before the resource identifier (see example below).
  11. Click the OutputData tab and tick the Output required check box.
  12. Click Send Test Message and enter the GUID of a Parent resource. This should return valid output XML. Click OK.
  13. Click “Infer…” followed by Validate Schema.
  14. Click OK on every open dialog to save all changes made to the web service configuration.

You can now use this new service and operation.

Example

This is simply an example of the URL which is required to get any tasks related to a contact. Note that there MUST be a forward slash before “ContactSet”; if this is not present when editing the URL, it should be added.

http://CRMServer1/CRMBase/XRMServices/2011/OrganizationData.svc/ContactSet(guid'{ContactID}’)\Contact_Tasks