Let's talk about the SugarCRM Upsert APIs - not to be confused with our company name. The upsert API endpoints are an incredible time saver. Have your integrations become cumbersome? Much like that 90's band Seven Mary Three, we want to avoid this scenario from happening whenever possible. Luckily for you, Sugar 10.2.0
supports upserting!
For those unfamiliar with the term, upsert is a concept that unifies two common operations:
Let's break down the flow that integrations had to use in the past:
GET /<module>/filter
to find a specific record by an integration IDPOST /<module>/
request to create a new record.PUT /<module>/<id>
request to update the record.Using the new APIs, you can now create or update your records with a single request!
This helps your integrations by having:
Funny you should ask; we have that all right here! Before we begin, it's best that you are familiar with SugarCRM's REST API, as you will need to be authenticated with an access token.
The integrate
endpoints are, by default, based on the sync_key
field that you will find in your modules starting in 10.2.0
. This field is used to store an external ID for records that you are syncing from another application. It is important to note that this field will need to be populated before you can use the other integrate
endpoints. Please note that if you installed the Sugar Essentials package prior to 10.2.0
, you will need to uninstall it. The Sugar Essentials package was originally created in order to add upsert endpoints. Now that they have been added to the core platform code, this package is no longer necessary. In fact, during an upgrade, package scanner will return an error if the package is installed.
To populate the sync field for a record, you can use the PATCH /integrate/<module>/:sync_key_field_name/:sync_key_field_value endpoint:
Request:
PATCH /integrate/Accounts/3b645ae2-1fd0-11eb-87c8-063b0cd98a86/sync_key/1234
Response:
{
"success": true
}
To fetch a record by its sync field, you can use the GET /Integrate/<module>/:sync_key_field_name/:sync_key_field_value endpoint:
Request:
GET /integrate/<module>/sync_key/1234
Response:
{
...
"id": "3b645ae2-1fd0-11eb-87c8-063b0cd98a86",
"sync_key": "1234",
"_acl": {
"fields": {}
},
"_module": "Accounts"
}
To create or update a record, you can use the PATCH /Integrate/<module>/:sync_key_field_name/:sync_key_field_value endpoint:
Request:
PATCH /integrate/Accounts/sync_key/1234?name=SugarCRM
Response:
{
"id": "3b645ae2-1fd0-11eb-87c8-063b0cd98a86",
}
To delete a record, you can use the DELETE /Integrate/<module>/:sync_key_field_name/:sync_key_field_value endpoint:
Request:
DELETE /integrate/Accounts/sync_key/1234
Response:
{
"id": "3b645ae2-1fd0-11eb-87c8-063b0cd98a86",
}
Was this "...too heavy, too light? too black or too white?" Tired of reading and just want something that works? Download the postman environment and collection.
Are you new to Sugar? Start a free trial today.
Please follow us on social media or subscribe to our RSS feed to keep up-to-date on new blog posts and announcements:
To read more about our company and services, please visit our home page.