Sage CRM

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

Post Image

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.

How to Update Records in SData 2.0

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.

Example 1: Updating a Company Name

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.

  1. URL:
  2. PATCH http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('18')



  3. JSON Request Body:
  4. {

     "Comp_Name": "Magnetic Solutions"

    }



Postman Setup:

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"

}



Example 2: Updating a Person Associated with a Company

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.

  1. Query the Company:
  2. To retrieve information about the company and its associated people, use the following GET request:
  3. GET http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('19')



  4. The response will include a list of people associated with the company:
  5. {

     "companyID": "19",

     "Comp_Name": "Tech Innovators",

     "$resources": [

       {

         "Pers_FirstName": "Jane",

         "Pers_LastName": "Smith",

         "PersonID": "5"

       }

     ]

    }



  6. Now that we know the PersonID for the individual we want to update, we can proceed.
  7. Updating the Person:
  8. To change the first and last name of this person to John Doe, you’ll use the PATCH method on the person’s record.
  9. URL:
  10. PATCH http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Person('5')



  11. JSON Request Body:
  12. {

     "Pers_FirstName": "John",

     "Pers_LastName": "Doe"

    }



Response:

After sending the request, you’ll receive a response confirming the person’s updated details:

{

 "PersonID": "5",

 "Pers_FirstName": "John",

 "Pers_LastName": "Doe"

}



Handling Navigation URLs

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.

Closing Thoughts

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!