Using SData 2.0 in Sage CRM: Part 4 - Deleting records

This is the fourth post in a series of posts documenting how to use the new SData 2.0 RESTful API in Sage CRM. If you haven't

This is the fourth post in a series of posts documenting how to use the new SData 2.0 RESTful API in Sage CRM.  If you haven't read the first post then I highly suggest that you do as the following posts all build on concepts presented in that one.

In SData 2.0, we are able to manipulate data which was not possible before.  One of these manipulations is deleting data from the Sage CRM database.

Syntax of a delete

Just like all the other data manipulation we have done, we delete data using the DELETE REST verb. We specify the ID of the record that we want to delete in the URL (the URL is the same as selecting an entity by its ID).

The response will be blank.

Examples

Deleting a company

In our first example we will delete a company in the Sage CRM database.  As mentioned earlier, the URL is exactly the same as querying a company by its ID.  The difference is in the verb that we use.  In this case it will be DELETE, making our queries as follows (in this example we are deleting company with an ID of 1224):

DELETE http://{Server Name}/sdata/{Install Name}j/sagecrm2/-/Company('1224') 

If we Send this request, we should get back a blank response:

Deleting an email address belonging to a company

In this example we are going to delete the email address for a company.  To do so, we first have to query the email address assigned to the company so that we can get its ID.  We can do this with the following query (this will select the email address assigned to company 1225):

GET http://{Server Name}/sdata/{Install Name}j/sagecrm2/-/Company('1225') 

The results contain the ID of the email record:

We can now use this ID in the following query to delete the email record:

DELETE http://{Server Name}/sdata/{Install Name}j/sagecrm2/-/Email('2111')

If you received a blank response then the email address should have been deleted successfully.

Closing

I hope this post has shed more light on the power available in SData 2.0.  Please let me know if you have any questions or comments by contacting me.  Also please let me know how you are implementing SData 2.0 in cool ways in your own project!