Salesforce REST API Integration Guide: 2 Simple Methods

January 2, 2025
20 min read

Salesforce is a leading cloud-based Customer Relationship Management (CRM) platform that empowers you to streamline sales, marketing, and customer data. However, as your business grows, you may rely on data from various applications to manage multiple aspects of your operations, like accounting and project management.

These applications often operate independently and may not integrate with Salesforce, resulting in data silos and inefficient workflows. When customer data is fragmented across diverse systems, it is difficult to gain a holistic view of your customers.

To address these challenges, Salesforce provides a robust REST API that enables external applications to integrate with Salesforce. Let’s look into how to integrate with Salesforce API for better data management.

What is Salesforce REST API?

The Salesforce REST (Representational State Transfer) API is a web-based interface that allows external applications to access and interact with Salesforce data. This API uses resources, such as individual records, collections of documents, or metadata, representing various data entities within Salesforce. Each resource is accessible via a unique Uniform Resource Identifier (URI), which can be accessed by sending HTTP requests to the corresponding URI.

Salesforce REST API

By using standard HTTP methods, the REST API helps you perform CRUD operations and execute SOQL(Salesforce Object Query Language) queries to interact with Salesforce data. The API supports both XML and JSON formats for data exchange, making it versatile for different application needs.

Benefits Of Using Salesforce REST API Integration

Salesforce REST API integration offers numerous benefits that can significantly enhance your business operations. Here are some key advantages:

Real-Time Data Synchronization

Salesforce REST API facilitates real-time synchronization of data across various applications. For instance, when a sales representative updates customer information in Salesforce, the changes are immediately reflected in connected systems. This eliminates data silos, ensures consistent information across platforms, and enhances team collaboration by providing access to the latest data.

Improved Data Accuracy

The Salesforce REST API integration improves data accuracy by centralizing information management. This single source of truth for customer information facilitates better analysis, enabling you to make strategic decisions with reliable data.

Enhanced Security

The Salesforce REST API ensures secure data access through robust features like OAuth 2.0, which uses token-based authentication to prevent unauthorized access. This safeguards sensitive information while enabling secure interaction with Salesforce resources.

Improved Customer Experience

Salesforce data integration lets you connect CRM with other applications, such as marketing, sales, and customer support systems. For instance, customer support teams can resolve issues more efficiently by accessing relevant customer data in real time. This responsiveness boosts customer satisfaction and loyalty.

Data You Can Fetch From Salesforce Using REST API

You can retrieve different types of data from Salesforce using the REST API. Here are a few examples:

  • Records that are based on a specified object type and record ID.
  • Metadata for an object, including details about each field, URLs, and relationships.
  • Individual field values from a record within a standard Salesforce object.
  • List of deleted/updated records for a specified object.
  • Search result layout configuration for each object.
  • User passwords that are based on the specified user ID.

Understanding Salesforce REST API Basics

Here is a brief overview of the basics of Salesforce REST API.

API HTTP Methods

The Salesforce REST API supports standard HTTP request methods. Below are some of the primary methods that help you perform different operations on resources:

  • GET: Used to retrieve data from Salesforce.
  • PUT: To update an existing record.
  • POST: Used to create a new record or resource.
  • DELETE: To remove a specific record.

API Status Codes

Here are some of the HTTP status codes returned by the server to indicate the result of an API request:

  • 200: OK, Successful request.
  • 401 (Unauthorized): Authentication failed, often due to invalid credentials.
  • 404 (Not Found): The requested resource is not found on the server.
  • 500 (Internal Server Error): An error has occurred on the server, so the request couldn’t be completed.

API Headers

Headers are used to customize HTTP requests. The Salesforce REST API supports several standard and custom headers. Some examples include:

  • HTTP Content-Type: This indicates the format of the request body that you attach to the request, such as application/json or application/xml.
  • HTTP Authorization: This header type provides the OAuth 2.0 access token to authorize the client.

API Request Body

A request body is where you include additional details, like field values, for creating or updating records. It can be in either JSON or XML format. However, when accessing resources with the GET method, there is no need to attach a request body.

Steps to Fetch Data From Salesforce REST API Integration

Follow the step-by-step instructions outlined below to integrate with Salesforce API and retrieve data successfully.

Step 1: Set Up a Salesforce Account

  • To get started, first sign up for a free account on Salesforce Developer Edition.
Set up Salesforce Account

Step 2: Generate Salesforce REST API Credentials

To integrate with Salesforce API, set up a new Connected App. This app will provide you with the credentials needed to authenticate your API requests. Follow the below steps:

  • Sign in to your Salesforce account and click the gear icon located in the top-right corner to access Setup.
  • Navigate to Setup -> Home -> Platform Tools -> Apps -> App Manager, and then click on New Connected App.
Salesforce App Manager
  • Fill in the required fields and check the Enable OAuth Settings checkbox to enable OAuth2 authentication.
Enable OAuth Settings
  • Finally, save all the app settings. After creating the Connected App, you’ll receive the Consumer Key (Client ID) and Consumer Secret (Client Secret), which are essential for authentication with Salesforce REST API.

Step 3: Obtain an Access Token

The Salesforce REST API requires a valid access token to send requests. To get this token, use the username-password authorization flow, which is a straightforward way to authenticate. You can use cURL (client URL) to make requests to Salesforce. cURL is a command line tool that helps you transfer data to and from a server. It supports various protocols, including HTTP and HTTPS, and runs on almost every platform.

  • Open the terminal and run the following cURL commands to send a request to the Salesforce OAuth endpoints.
curl -X POST https://login.salesforce.com/services/oauth2/token \
-d 'grant_type=password' \
-d 'client_id=your_consumer_key' \
-d 'client_secret=your_consumer_secret' \
-d 'username=your_username' \
-d 'password=your_password'

Replace your_consumer_key, your_consumer_secret, your_username, and your_password with your actual credentials.

  • After validating the client credentials, Salesforce returns a response in JSON format containing an access token. Here’s an example:
{
"access_token":"00D5e000001N20Q!ASAAQEDBeG8bOwPu8NWGsvFwWNfqHOp5ZcjMpFsU6yEMxTKdBuRXNzSZ8xGVyAiY8xoy1KYkaadzRlA2F5Zd3JXqLVitOdNS",
 "instance_url": "https://ap1.salesforce.com"
 "id": "https://login.salesforce.com/id00D5e000001N20QEAS/0055e000003E8ooAAC",
 "token_type": "Bearer",
 "issued_at": "1461366505710",
 "signature": "duQ2eUY6gvuKTkF/RRahtEhcQY6QU7asgrq7UVqXyc8="
}

Step 4: Fetch Data Using the Salesforce REST API

After acquiring the access token, you can now use it to make API requests to fetch Salesforce data. Here’s how to structure your requests:

  • Incorporate the access token in the request headers for authentication. The format for the header is as follows:
Authorization: Bearer <access_token>

Replace access_token with the actual token you received in the previous step.

  • For example, to fetch metadata for a specific Salesforce object (e.g., Account), you can use the sObject Basic Information resource. Here is the request format:
curl https://MyDomainName.my.salesforce.com/services/data/v62.0/sobjects/Account/ -H "Authorization: Bearer <access_token>"
  • If the request is successful, you'll get a response containing metadata about the Account object, as shown below:
	{
  "objectDescribe" :
  {
    "name": "Account",
    "updateable": true,
    "label": "Account",
    "keyPrefix": "001",

    ...

    "replicateable": true,
    "retrieveable": true,
    "undeletable": true,
    "triggerable": true
  },
  "recentItems":
  [
    {
      "attributes":
      {
        "type": "Account",
        "url": "/services/data/v62.0/sobjects/Account/001D000000INjVeIAL"
      },
      "Id": "001D000000INjVeIAL",
      "Name": "Example Account Name"
    }
  ]
}

Handling & Storing the Salesforce REST API Response Data

Effectively handling and storing Salesforce REST API response data is essential for ensuring the efficiency and reliability of your applications. Here are the steps to do so:

Parse the Response

Once you receive the API response in JSON format, parse the data into a usable structure. Most programming languages provide libraries for this purpose. For example, in JavaScript, you can utilize the JSON.parse() method to convert a JSON string into data structures like maps or objects. This allows easy access to individual data points. In Python, you can use the json.loads() function for parsing.

Error Handling

Monitor the HTTP status codes returned by the server to identify issues such as authentication failures or invalid requests. By logging these errors, you can create a robust debugging and monitoring system that aids in addressing problems effectively.

Data Validation

Before you store the parsed data, validate it to make sure it’s in the expected format and has all the required fields. Validating the data will prevent errors in downstream processes and ensure only high-quality data is stored.

Data Storage & Caching

Choose the right data storage solution based on your application’s needs. For structured data, you can opt for relational databases like MySQL or PostgreSQL. Conversely, for unstructured or semi-structured data, you can opt for NoSQL databases like MongoDB.

You can also implement caching to improve performance and minimize the number of API calls to Salesforce. Caching allows you to store frequently accessed data in memory, so you don’t have to fetch the same data repeatedly.

Salesforce REST API Vs. Bulk API Integration

For integrating with external systems, Salesforce provides two primary APIs: the REST API and the Bulk API. Here's a concise summary to help you decide the right API for your use case:

Salesforce REST API

Use Case: Ideal for applications requiring real-time data access and manipulation, such as web and mobile applications.

Data Volume: Best suited for smaller data sets, typically under 2,000 records per request.

Synchronous Processing: Operates synchronously, as the request is processed immediately, and a response is returned in real-time.

Salesforce Bulk API

Use Case: Designed specifically for large-scale data operations, such as data migrations or batch updates, where high volumes of records need efficient processing.

Data Volume: Capable of processing batches of up to 10,000 records per request with the Bulk API and even larger batches with Bulk API 2.0.

Asynchronous Processing: Salesforce operates asynchronously; batches are processed in the background, and results are returned when the processing is complete. 

Airbyte: A Reliable Solution for Salesforce Data Integration

Integrating with Salesforce through REST API can be challenging, especially for those without technical expertise. To simplify this process, you can leverage no-code data integration tools like Airbyte, which offers a more flexible and automated approach for fetching data from Salesforce.

Airbyte offers an extensive catalog of 550+ pre-built connectors, including Salesforce. These connectors enable you to sync data from Salesforce to your preferred destination without the need for extensive coding knowledge.

To fetch data from Salesforce using Airbyte, follow these simple steps:

  • Setup Salesforce as a Source Connector: Start by choosing Salesforce from the list of available source connectors in Airbyte.
  • Setup Your Destination Connector: Set up the destination connector where you want to send the data, such as a data warehouse or database.
  • Configure the Salesforce Connection: Select the specific streams and columns you want to extract and the sync frequency. You can choose between different sync modes based on your needs—either full refresh for fetching all data or incremental syncs to update only the latest changes.
Salesforce to Any Destination with Airbyte

Key Features of Airbyte

Custom Connectors: If you don't find the connector you need from the available list, Airbyte enables you to build custom connectors within 30 minutes with its easy-to-use Connector Development Kit (CDK). You can also leverage Airbyte’s AI-powered Connector Builder to speed up the development process.

GenAI Workflows: Airbyte facilitates integration with popular vector stores, including Pinecone, Qdrant, Chroma, Milvus, and more. This empowers you to simplify your AI workflows by loading semi-structured and unstructured data directly to vector store destinations.

Customizable Data Selection: You can filter specific Salesforce objects and fields for replication, enabling targeted data extraction based on your requirements.

Extensive Salesforce Support: The Salesforce connector within Airbyte supports both Standard and Custom objects. Each object is read as an individual stream, facilitating granular control and data manipulation.

Sync Resilience: Airbyte's Record Change History feature helps avoid synchronization failures caused by problematic rows, like oversized or invalid records. If any record breaks the sync, Airbyte modifies it during transit, logs the changes, and guarantees that the sync completes successfully.

Automatic Schema Detection: With Airbyte, you can set up automatic schema change detection that updates your destination based on changes in the source. This ensures that any updates in Salesforce are instantly reflected in your target system.

Conclusion

Integrating Salesforce with external applications ensures data flow and connectivity, which is essential for optimizing your business processes.

In this article, you have explored two methods to integrate with Salesforce API. By leveraging these integration techniques, you can break down data silos, improve collaboration, and gain a comprehensive view of your customer journey.

Limitless data movement with free Alpha and Beta connectors
Introducing: our Free Connector Program
The data movement infrastructure for the modern data teams.
Try a 14-day free trial