REST API is an API that follows a set of rules for an application and services to communicate with each other. As it is constrained to REST architecture, REST API is referred to as RESTful API. REST APIs provide a way of accessing web services in a flexible way without massive processing capabilities. Salesforce REST API is used to access Salesforce data without the use of the actual tool.

In this blog, you will understand the complete workings of Salesforce REST API. The steps involved in setting up Salesforce REST API will be elaborated with examples. The types, operations, and limits of Salesforce REST API are also discussed in detail.

Introduction to Salesforce REST API

Salesforce REST API: Salesforce REST API logo

Salesforce is a cloud-based Customer Relationship Management (CRM) tool that is designed to support companies in managing their Sales and Customer related data. You can use the Salesforce CRM without any technical background as it is easy to set up and manage.

Salesforce REST API gives you an option to access Salesforce data without the actual user interface. REST API Salesforce allows you to integrate Salesforce with other Apps and perform all the operations. 

Salesforce REST API provides a straightforward and sustainable interface with its RESTful architecture. REST API Salesforce tools allow you to create, manipulate, and search for data in Salesforce. This is done by sending HTTP requests to endpoints in Salesforce.

With Salesforce REST API, you can access and work with resources like records, query results, metadata, etc. The main reason for using REST API Salesforce is that it provides an ample amount of functions with fewer tooling requirements to access data from Salesforce.

Streamlining Salesforce REST API Configuration with Hevo

Hevo simplifies the process of setting up the Salesforce REST API by automating data integration workflows. Migrating your data can become seamless with Hevo’s no-code intuitive platform. With Hevo, you can:

  1. Automate Data Extraction: Effortlessly pull data from 150+ connectors like Salesforce(and other 60+ free sources).
  2. Transform Data effortlessly: Use Hevo’s drag-and-drop feature to transform data with just a few clicks.
  3. Seamless Data Loading: Quickly load your transformed data into your desired destinations, such as BigQuery.

Try Hevo and join a growing community of 2000+ data professionals who rely on us for seamless and efficient migrations.

Get Started with Hevo for Free

Salesforce REST API resources and requests

The REST API Salesforce depends on the resources. These resources include records, query results, metadata, or API information. You can access each resource by sending HTTP requests to the corresponding Uniform Resource Identifier (URI) of the resource. You will have to frame an HTTP request based on the resource you wish to access. The structure of the requests in REST API Salesforce consists of the following elements:

URI

A Uniform Resource Identifier (URI) is the route to a resource in Salesforce. The basic structure of URI is the same, but each resource has its unique URI. The structured format of a URI is given below:

https://MyDomainName.my.salesforce.com/services/data/vXX.X/resource/

In the place of MyDomainName, add your Salesforce org’s subdomain. Replace vXX.X/ with your API’s version. Add your resource path in the place of the resource.

HTTP method

REST API Salesforce supports HTTP request methods. These HTTP methods include the commands like HEAD, GET, POST, PATCH, PUT, and DELETE.

Headers are used to customize HTTP requests. REST API Salesforce supports standard as well as custom headers. However, these custom headers must be related to Salesforce. Some of the most frequently used headers in REST API Salesforce include:

  • HTTP Content-type: This header points out the request body format attached to the request. For example, application/XML and application/json.
  • HTTP Accept: This header type shows the client accepts format for the response body. The default value is application/json.
  • HTTP Authorization: This header type gives the OAuth 2.0 access token to authorize your client.
  • Compression header: This header type compresses the request.
  • Conditional request header: This header type verifies the records that are accessed against a precondition.

Request body

The request body is a field in REST API Salesforce that allows you to add extra details to complete the request. The request body can add new records or field values to an existing record. A request body in REST API Salesforce can be in either JSON or XML format.

Working with Salesforce REST API

Step 1: Salesforce REST API Pre-requisites

You need to complete all the following prerequisites before starting with Salesforce REST API. The Salesforce REST API Pre-requisites include:

Step 1.1: Sign Up for Developer Edition

To get started with Salesforce REST API, sign up for Developer Edition. This Developer Edition is best suited to get started with testing and development. After signing up for Developer Editon, they’ll mail you the password information.

Step 1.2: Ensure API Enabled Permission

Follow the instructions in User Permission given in Salesforce Help. Ensure that API is enabled in your user profile.

Enable OAuth Settings

Step 1.3: Create a Connected App

You can create a Connected App and configure it according to your needs. Before this, you need to configure basic connected App settings and enable the OAuth settings for API integration.

Connected App

Step 1.4: Acquire Consumer Key and Consumer Secret

To acquire the consumer key and consumer secret of the created connected App, follow these steps:

  1. Select App Manager from Setup.
  2. Select View from the dropdown menu of the connected App that you have created.
  3. In case the consumer key and consumer secrets are hidden, select Click to reveal and copy them.
Get Consumer Details

Step 2: Salesforce REST API setting up authorization

The next step in Salesforce REST API is to set up authorization. The Salesforce REST API requires an access token to send requests. With the username-password authorization flow that can be used with cURL, you can get access to this token. When you use OAuth authorization flow, you need not add credentials in the request.

1. OAuth Token Request

The following request template can be used to send requests to the Salesforce OAuth endpoints.

curl https://MyDomainName.my.salesforce.com/services/oauth2/token -d 'grant_type=password' -d 'client_id=consumer-key' -d 'client_secret=consumer-secret' -d 'username=my-login@domain.com' -d 'password=my-password'

Replace the following elements in the template as given below:

  • MyDomainName: Your Salesforce.org domain
  • consumer-key and consumer-secret: Your consumer key and consumer secret values that you’ve copied during the pre-requisites set up
  • my-login@domain.com : Your login id for your Salesforce org
  • my-password: Your login password

2. Successful Response

After your request becomes successful, you will receive the access token in the Salesforce REST API response.

Here is an example:

{"access_token":"00D5e000001N20Q!ASAAQEDBeG8bOwPu8NWGsvFwWNfqHOp5ZcjMpFsU6yEMxTKdBuRXNzSZ8xGVyAiY8xoy1KYkaadzRlA2F5Zd3JXqLVitOdNS",
 "instance_url":"https://MyDomainName.my.salesforce.com",
"id":"https://login.salesforce.com/id/00D5e000001N20QEAS/0055e000003E8ooAAC,
 "token_type":"Bearer",
 "issued_at":"1627237872637",
 "signature":"jmaZOgQyqUxFKAesVPsqVfAWxI62O+aH/mJhDrc8KvQ="}
Integrate Salesforce to BigQuery
Integrate Salesforce to Redshift
Integrate Salesforce to Snowflake

Salesforce REST API Operations

Salesforce REST API can be used to perform the following Operations,

To get the Salesforce Version

The Salesforce REST API requests to see the available Salesforce versions.

curl https://MyDomainName.my.salesforce.com/services/data/

The corresponding Salesforce REST API example response with a header. This output has all the valid Salesforce versions.

Content-Length: 88 
Content-Type: application/json; 
charset=UTF-8 Server:
[
    {
        "label":"Spring '11",
        "url":"/services/data/v21.0",
        "version":"21.0"
    }
    ...
]

To get a list of resources

To get a list of resources, the following examples of Salesforce REST API requests can be used.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

Salesforce REST API response will give you the list of all the available resources.

{
    "sobjects" : "/services/data/v53.0/sobjects",
    "search" : "/services/data/v53.0/search",
    "query" : "/services/data/v53.0/query",
    "recent" : "/services/data/v53.0/recent"
}

To retrieve the list of available objects

To get a list of available objects, the following examples of Salesforce REST API requests can be used. You must submit a Describe Global request.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

REST API Salesforce response will give you the list of all the available objects.

Transfer-Encoding: chunked 
Content-Type: application/json; 
charset=UTF-8 Server:
{
 "encoding" : "UTF-8",
 "maxBatchSize" : 200,
 "sobjects" : [ {
    "name" : "Account",
    "label" : "Account",
    "custom" : false,
    "keyPrefix" : "001",
    "updateable" : true,
    "searchable" : true,
    "labelPlural" : "Accounts",
    "layoutable" : true,
    "activateable" : false,
    "urls" : { "sobject" : "/services/data/v53.0/sobjects/Account",
    "describe" : "/services/data/v53.0/sobjects/Account/describe",
    "rowTemplate" : "/services/data/v53.0/sobjects/Account/{ID}" },
    "createable" : true,
    "customSetting" : false,
    "deletable" : true,
    "deprecatedAndHidden" : false,
    "feedEnabled" : false,
    "mergeable" : true,
    "queryable" : true,
    "replicateable" : true,
    "retrieveable" : true,
    "undeletable" : true,
    "triggerable" : true },
   },
...

To get basic object information

You need to submit a sObject Basic information request to get basic information of the metadata.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

The basic features of the account object can be seen in the REST API Salesforce response.

{
    "objectDescribe" : 
    {  
        "name" : "Account",  
        "updateable" : true,  
        "label" : "Account",  
        "keyPrefix" : "001",  
        
        ...
        
        "replicateable" : true,  
        "retrieveable" : true,  
        "undeletable" : true,  
        "triggerable" : true
    },
    "recentItems" : 
    [ 
        {  
            "attributes" : 
            {    
                "type" : "Account",    
                "url" : "/services/data/v53.0/sobjects/Account/001D000000INjVeIAL"  
            },  
            "Id" : "001D000000INjVeIAL",  
            "Name" : "asdasdasd"
        }, 

        ...

    ]
}

To get a list of Fields

To get a list of fields, the following REST API request can be used. You can get more elaborate info on submitting a sObject Describe request.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/describe/ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

The output response of this request is given below. The field attributes and child relationships of the account objects can be seen here.

{
    "name" : "Account",
    "fields" : 
    [
        {
            "length" : 18,
            "name" : "Id",
            "type" : "id",
            "defaultValue" : { "value" : null },
            "updateable" : false,
            "label" : "Account ID",
            ...
        },
        ...
    ],
    "updateable" : true,
    "label" : "Account",
    ...
    "urls" : 
    {  
        "uiEditTemplate" : "https://MyDomainName.my.salesforce.com/{ID}/e",  
        "sobject" : "/services/data/v53.0/sobjects/Account",  
        "uiDetailTemplate" : "https://MyDomainName.my.salesforce.com/{ID}",  
        "describe" : "/services/data/v53.0/sobjects/Account/describe",  
        "rowTemplate" : "/services/data/v53.0/sobjects/Account/{ID}",  
        "uiNewRecord" : "https://MyDomainName.my.salesforce.com/001/e"
    },
    "childRelationships" : 
    [ 
        {  
            "field" : "ParentId",  
            "deprecatedAndHidden" : false,  
            ...
        }, 
        ...
    ],
     
    "createable" : true,
    "customSetting" : false,
    ...
}

To execute a SOQL Query

After you have all the account objects, you can use the SOQL query to get the list of account name values. To do this, you need to submit a query request.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/query?q=SELECT+name+from+Account -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

The output response consists of the Account name along with other attributes.

{
    "done" : true,
    "totalSize" : 14,
    "records" :
    [
        {
            "attributes" :
            {
                "type" : "Account",
                "url" : "/services/data/v53.0/sobjects/Account/001D000000IRFmaIAH"
            },
            "Name" : "Test 1"
        },
        {
            "attributes" :
            {
                "type" : "Account",
                "url" : "/services/data/v53.0/sobjects/Account/001D000000IomazIAB"
            },
            "Name" : "Test 2"
        },
        ...
    ]
}

To a field on a Record

You must submit a sObject request to update an attribute. To update an object, you need to first create a text file named patchaccount.json with the details that need to be updated.

{
    "BillingCity" : "Fremont"
}

The following request can be used to update a record.

curl https://MyDomainName.my.salesforce.com/services/data/v53.0/sobjects/Account/001D000000IroHJ -H "Authorization: Bearer access_token" -H "X-PrettyPrint:1" -H "Content-Type: application/json" --data-binary @patchaccount.json -X PATCH

In the response, you will have only the headers. Once you refresh the page, you’ll find the object being updated.

HTTP/1.1 204 No Content
Server: 
Content-Length: 0

Conclusion

From this blog, you completely understand the workings of Salesforce REST API. The steps involved in setting up Salesforce REST API will be elaborated with examples that will be clear to you now. In addition, you would have also learned about its types and operations. To delve deeper into this subject, Explore our Salesforce Apex REST API.

Hevo Data offers a faster way to move data from 150+ Data Sources such as REST API for free, into your Data Warehouse to be visualized. Hevo is fully automated and, hence, does not require you to code. Hevo provides a pre-built Native REST API Connector that will allow you to integrate data from a plethora of custom and non-native sources. All this is done without writing a single line of code and free of cost.

Want to take Hevo for a spin? Sign Up here for a 14-day free trial and experience the feature-rich Hevo suite firsthand. You can also have a look at the unbeatable pricing that will help you choose the right plan for your business needs.

Frequently Asked Questions

1. What is the REST API in Salesforce?

The REST API in Salesforce is a web service interface that allows you to interact with Salesforce data and functionality over HTTP.

2. What are REST API examples?

Include GET, POST, PATCH, and DELETE requests for data retrieval, creation, update, and deletion.

3. What is an example of a Salesforce API, and how is it used?

Retrieving a list of contacts involves sending a GET request to the /services/data/vXX.X/sobjects/Contact endpoint, which returns contact data that can be used for integration or reporting. Read about salesforce object APIs to access information about Salesforce objects

Sherly Angel
Business Analyst, Hevo Data

Sherly is a data analyst with a passion for data analysis and architecture. Currently a Business Analyst at Hevo Data, she specializes in advanced analytics tools like Tableau and Python, harnessing them to drive data-driven decision-making. With a Master's in Healthcare Data Analytics and a PGP in Data Science, Sherly excels in designing scalable data solutions that optimize business processes and enhance operational efficiency.