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.
PATCH http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('18')
{
"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.
GET http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('19')
{
"companyID": "19",
"Comp_Name": "Tech Innovators",
"$resources": [
{
"Pers_FirstName": "Jane",
"Pers_LastName": "Smith",
"PersonID": "5"
}
]
}
PATCH http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Person('5')
{
"Pers_FirstName": "John",
"Pers_LastName": "Doe"
}
After sending the request, you’ll receive a response confirming the person’s updated details:
{
"PersonID": "5",
"Pers_FirstName": "John",
"Pers_LastName": "Doe"
}
When querying records related to a company or person, SData 2.0 provides navigation URLs to simplify access to related data. However, if you're working across networks or have specific URL configurations, the navigation URLs may not always function as expected. In such cases, it’s often easier to manually construct URLs by appending the record ID directly.
For example, if you retrieve a person's details using the company query, you might encounter navigation issues if your network or environment is set up differently. In such scenarios, manually editing the URL—such as appending the PersonID to a known working base URL—can help you retrieve or update the record more reliably.
Updating data using SData 2.0 provides a powerful way to integrate with Sage CRM, allowing businesses to dynamically modify records. Whether you're updating simple fields like company names or handling more complex tasks such as managing associated people, SData 2.0 makes the process efficient and seamless.
Stay tuned for the next part of this series, where we’ll explore how to create new records in Sage CRM using SData 2.0. If you have any questions or need further assistance with SData 2.0, feel free to reach out!