sugarcrm v10 REST API Basic CRUD operations


Example

First, ensure you log in, and add the access_token to your request header.

In this example, we're going to do some basic operations to access records. These use the Accounts module as an example, but other standard and custom modules (i.e. Leads, Contacts, Opportunities) behave in the same way.

Create

To create an Account, we need to make a post request to the Accounts endpoint, with the details we want to add. Upon success, this returns an object containing the new record's ID, and the current data.

POST https://YOURSITE.com/rest/v10/Accounts
{
"name":"My New Account"
}

Read

First, we'll retrieve the record we just created, for me the Id was "9174c58c-409c-11e7-bfdf-00163ef1f82f" so to retrieve all information for the record, we do the following:

GET https://YOURSITE.com/rest/v10/Accounts/9174c58c-409c-11e7-bfdf-00163ef1f82f

That sure is a large object! What about just seeing the name, and the date I just created it?

GET https://YOURSITE.com/rest/v10/Accounts/9174c58c-409c-11e7-bfdf-00163ef1f82f?fields=name,date_entered

Much better. But what if I have thousands of Accounts in the system already, and haven't managed to remember the GUID for it?

GET https://YOURSITE.com/rest/v10/Accounts?fields=name,date_entered&filter[0][name]=My New Account

Update

So what if I decided I wanted to change something on the app? What about changing the name, and adding a description?

PUT https://YOURSITE.com/rest/v10/Accounts/9174c58c-409c-11e7-bfdf-00163ef1f82f
{
    "name":"My Updated Account",
    "description":"Updated via REST API"
}

Delete

Okay, that's all fine, but let's clear this up before putting real data in:

DELETE https://YOURSITE.com/rest/v10/Accounts/9174c58c-409c-11e7-bfdf-00163ef1f82f