February 17, 2019 · Sage CRM SData SData 2.0 Integration

Using SData 2.0 in Sage CRM: Part 2 - Updating records

This is the second part of a series of articles on how to use SData 2.0 in Sage CRM.  If you haven't read the first one then I suggest you read it as it provides a grounding for the concepts we will be covering in this article and the ones going forward.  A list of all the articles can be found at the bottom of this post.

One of the new features in SData 2.0 is the ability to modify records in the Sage CRM database.  In this article we will be covering how to update a record with new information.  We will be continuing with the Company demo data that we were using in the first article of this series.

Syntax of an update

Since the SData 2.0 API is a RESTful API, we are able to use RESTful verbs to update a record.  With SData 2.0, we are required to use the PATCH verb along with the ID of the record to update in the URL.  The body of the request must be raw JSON containing the field names that should be changed along with their values.

The response is a JSON object containing the ID of the record that has been updated and the value of the new fields.

Examples

Update company name

The most basic example we will cover is updating a company name.  In this case, I want to update the company with ID 18 to have a name of Magnetic Solutions.  To do this I will call the following URL:

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

My request body (which is raw JSON) will look as follows:

{
    "Comp_Name": "Magnetic Solutions"
}

In Postman, it should look something like this:

When you send the request, you should get back a response looking something like this:

Updating the person name associated with a company

Let's say we want to update the name of the person associated with a company in Sage CRM.  To do this, we first have to query the company that the person belongs to.  To do this execute the following query:

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

When we look in the results we can see the person reference.  In this case we will just be updating the primary person associated with the company:

We can simply send a PATCH request to the specified Reference URL.  The body will contain the updated name for the person:

A word of warning: be careful of using the navigation URLs as they can sometimes be incorrect depending on if you are calling SData 2.0 from an external network or not.  If you can't be sure that the URL will always be correct, rather retrieve the ID of the person and construct the URL to call yourself.

When we send the request we should get a response similar to the following to indicate that the update was successful:

Closing

As you can see, updating data opens up endless opportunities for integrating with Sage CRM.  I hope this post has shed light on the power SData 2.0 provides you with regards to updating data in Sage CRM.

If you have any questions regard SData 2.0, please feel free to contact me.

Disclaimer

This is a repost of my original article on Astech's website here.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket