This is the second article in our SData 2.0 in Sage CRM series. If you haven't read the first part, I highly recommend starting there as it covers foundational concepts that we’ll build upon in this post. At the bottom of this page, you’ll find links to the other articles in the series.
In SData 2.0, one of the most valuable features is the ability to modify existing records within Sage CRM. In this article, we’ll explore how to update records using the PATCH method in SData 2.0, continuing with the company demo data from Part 1.
As a RESTful API, SData 2.0 utilizes REST methods to interact with the Sage CRM database. To update a record, you use the PATCH verb along with the record's ID in the URL. The request body must be in JSON format, specifying the fields you want to modify and their new values.
The API will return a response confirming the update, typically including the updated fields and the record’s ID.
Let’s begin with a simple example: changing the name of a company. Suppose you want to update the name of the company with ID 18 to Magnetic Solutions.
URL:
PATCH http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('18')
JSON Request Body:
{
"Comp_Name": "Magnetic Solutions"
}
Using Postman, you would create a new PATCH request with the URL above, set the request body to raw JSON, and include the JSON data that updates the company name.
Once you send the request, you should receive a response confirming the update, like the following:
{
"companyID": "18",
"Comp_Name": "Magnetic Solutions"
}
Now, let’s update the details of a person associated with a specific company. First, we’ll need to query the company to identify the person’s reference.
Query the Company:
To retrieve information about the company and its associated people, use the following GET request:
GET http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('19')
The response will include a list of people associated with the company:
{
"companyID": "19",
"Comp_Name": "Tech Innovators",
"$resources": [
{
"Pers_FirstName": "Jane",
"Pers_LastName": "Smith",
"PersonID": "5"
}
]
}
Now that we know the PersonID for the individual we want to update, we can proceed.