Sage CRM

Using SData 2.0 in Sage CRM: Part 3 - Inserting records

Post Image

Welcome to the third installment of our SData 2.0 in Sage CRM series. In this post, we’ll explore how to create new records using the SData 2.0 API. If you haven’t already, be sure to check out Part 1 and Part 2 for foundational knowledge on querying and updating records.

Inserting New Records in Sage CRM

One of the powerful features of SData 2.0 is the ability to insert new records into the Sage CRM database. To do this, we use the POST method, specifying the entity in the URL and including the new data in the request body formatted as JSON.

Example 1: Creating a New Company

Let’s start by creating a new company called Joe’s Donuts in Sage CRM.

  1. URL:
  2. POST http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company



  3. JSON Request Body:
  4. {

     "Comp_Name": "Joe's Donuts",

     "Comp_Type": "Customer"

    }



After sending this request using a tool like Postman, you’ll receive a response confirming the creation of the new company, along with its assigned ID in the database.

Example 2: Creating a Note for the Company

Now that we’ve created a company, let's add a note to Joe’s Donuts. You’ll need the Company ID (let’s assume it’s 1226) and set up the request as follows:

  1. URL:
  2. POST http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Notes



  3. JSON Request Body:
  4. {

     "Note_Note": "Customer-focused. Solutions should enhance their experience.",

     "Note_ForeignTableId": 5,

     "Note_ForeignId": 1226

    }



Sending this request will return a response confirming that the note has been added successfully.

Example 3: Creating a New Person and Linking Them to the Company

This example is slightly more complex, as we’ll add a new person and link them to the company we just created. This involves two steps: first, creating the person, then creating a Person_Link record to associate them with the company.

Step 1: Create the Person

We’ll create the person Joe Palmolive:

  1. URL:
  2. POST http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Person



  3. JSON Request Body:
  4. {

     "Pers_FirstName": "Joe",

     "Pers_LastName": "Palmolive"

    }



When you send the request, the response will contain the ID of the new person, which you’ll need for the next step.

Step 2: Link the Person to the Company

To link Joe Palmolive to Joe’s Donuts, we need to insert a record into the Person_Link table. First, ensure that SData access to the Person_Link table is enabled by running the following SQL query:

UPDATE Custom_Tables SET Bord_SDataAccess = 'Y' WHERE Bord_Name = 'Person_Link'



After performing an IISRESET, the table will be accessible via SData. Then, send the following request to create the link:

  1. URL:
  2. POST http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Person_Link



  3. JSON Request Body:
  4. {

     "peli_type": "Admin",

     "peli_companyid": 1226,

     "peli_personid": 1780

    }



Once you send this request, the response will confirm the successful creation of the Person_Link record, associating Joe Palmolive with Joe’s Donuts as an Admin.

Verifying the Link

To ensure that the person was linked correctly, you can query the company to view all associated people:

  1. URL:
  2. GET http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company('1226')/Person



If everything was successful, you should see Joe Palmolive listed in the response.

Conclusion

SData 2.0 provides significant flexibility for inserting new records into Sage CRM, making it an essential tool for integration and automation. Whether you’re creating new companies, adding notes, or linking people to organizations, SData 2.0 streamlines the entire process, making it efficient and scalable.

In the next post, we’ll explore how to delete records using SData 2.0. Stay tuned!

If you have any questions about working with SData 2.0, feel free to reach out!