Any company working with Salesforce eventually faces the need to integrate and/or connect to an external or internal system. As a global provider, Salesforce has one of the most extensive sets of integration services. The major advantage of open source is Salesforce API Integration.
But first, what is an API? Its interface is a pre-written piece of code that can perform functions on a website or application. MuleSoft, which specializes in creating APIs, represents an API as a software mediator that permits two apps to communicate with each other. This approach provides flexibility in data manipulation and allows one to create, delete, or update records in Salesforce from an external program.
Table of Contents
Types of Salesforce APIs
There are many Salesforce APIs. However, they all work in the same way: They send data from another app to Salesforce, while simultaneously fetching data from Salesforce and moving it to another app.
- REST API: for sending and receiving information relating to REST.
- BULK API: for moving large amounts of data at the same time.
- Tooling API: for making custom development tools.
- Apex REST API: for executing REST API in APEX and providing Apex classes like RESTful web services.
- METADATA API: for managing building tools and settings.
- SOAP API: for server-side integrating.
- Apex SOAP API: for setting a custom web service and displaying the Apex classes similar to a SOAP web service.
- Streaming API: for data streaming that reflects data modification in Salesforce org.
- Chatter REST API: for entering chat channels and social data by REST.
Each of those Salesforce API integration tools is used in conjunction with an integration pattern to be highly scalable, maintainable, and reliable.
API Integration Benefits
Salesforce takes an API-driven approach to develop a wide range of functionality on its platform and offers the abilities to connect and interact with cloud services.
The primary benefit is that the user does not need to manually enter the same data in 2 different apps. The connect API Salesforce transfers information between Salesforce and the desired destination, saving time and effort for employees.
Another strong point is that reducing human involvement minimizes errors. With the Salesforce APIs, you only need to input data once; the program will do the rest.
APIs allow you to connect to many solutions, including e-commerce, EPR, and accounting software. In addition, APIs help sales teams collect information about their consumers and work within the broader organization.
This way, you can use the API to gain the consumer experience, streamline internal processes, or become an API provider so that developers and companies can profit from your technology (by paying you to do so).
How to Connect to Salesforce API?
You can do Salesforce integration API in the following ways:
This is a process required in both Salesforce and an external system. It provides the endpoint of the external system with which to integrate. Create a website and a connected application for customization.
This contains three classes that have corresponding methods to perform the corresponding functions to interact with other systems.
- HTTP to start an HTTP request and response.
- HTTP request via get (), delete (), put (), post ().
- HTTP response: to response sent by external systems (HTTP.send () operation).
To do this, you must write a custom web service using code, which can call the external environment, and grant access to our code and Force.com application.
There are two methods: Rest services () and Rest response ().
Our REST API guide Salesforce will focus on two types of API: REST and SOAP.
What Is the Salesforce SOAP API?
This standard protocol was originally designed for interoperability between apps built on various languages and platforms. Built-in rules extend its complexity and overhead, resulting in a long page load. However, it comes with a bonus built-in matching functionality, which is preferred for enterprise scenarios. These are isolation, security, consistency, and durability, and they are important to guaranteeing stable database transactions. SOAP uses a Web WSDL file to precisely define the criteria for accessing data throughout the API, and supports only XML. The main functionality of the SOAP API Sales Force is available through the REST API. The concept of WSDL is an XML document used to describe and interpret a SOAP web service request.
Force.com's native SOAP API lets users retrieve, create, delete, and update operations on Salesforce data from the app. Salesforce has two types of WSDL:
- Enterprise Web Services, created for Salesforce customers and their ISVs to create integrations specific to the Salesforce organization.
- Partner Web Services, designed for partners to work with various Salesforce organizations.
When Is the Apex SOAP API Used?
It is used if you need to expose Apex methods as SOAP web service APIs so that external systems get access to your code. It keeps both session ID for authorization and OAuth 2.0. To use the SOAP in your app, do the following:
- Open the "Integrations" folder.
- Press on SOAP and select Use SOAP Web Service.
- In the dialog that opens, specify the URL where you can find the WSDL.
- You must provide the exact URL when you input it in the web browser. Alternatively, you can import WSDL from your filesystem by specifying file: /// <filesystem path to wsdl>.
When you use a SOAP, you get:
- Public SOAP web service methods with input and output criteria.
- Structures for storing complex types defined in WSDL.
- XML data types translated to app data types.
Salesforce integration via web services API can be done using SOAP, but we prefer REST over SOAP because it is lightweight and supports XML and JSON, as opposed to SOAP, which supports only XML.
What Is the Salesforce REST API?
This set of architectural principles provides all kinds of Salesforce functionality throughout HTTP methods and REST resources. Salesforce integration using rest API has a response structure, is easy to use, and is indispensable in the context of mobile and web app development, the Internet of Things (IoT), and serverless computing.
The following important things can be done with Salesforce CRM integration API:
- Allow request access and transmission of Salesforce data.
- Permit the sending of data to Salesforce and get Salesforce data for the app.
- Access information about restrictions in your organization.
- Create, update, read, and delete records.
- Retrieve object metadata.
REST is data-dependent, while SOAP is feature-dependent. This is what the sample REST request to query all account ids and names looks like:
It can receive the response in XML or JSON format. This is what the JSON response format looks like:
Main Differences Between REST and SOAP
- The SOAP APIs are employed in large companies with legacy app backbones.
- The SOAP API is suited for situations in which an extensive amount of data needs to be transferred.
- SOAP is more language and platform-independent (REST needs HTTP).
- SOAP works in distributed enterprise ecosystems (REST implies a direct point-to-point connection).
- SOAP is more structured and fully typed than REST and provides significant extensibility before being assembled as WS * standards.
- SOAP offers automation when utilized with specific language products.
REST is more flexible and user-friendly. It has the next profit over SOAP:
- REST has easy-to-understand standards and a smaller learning curve.
- REST has built-in error handling.
- REST is faster and more productive (due to the small JSON message format) and does not require extensive processing. SOAP uses XML for all messages.
What Is a REST Resource?
In Salesforce com API guide, it is an abstraction of a piece of action or information such as a single data record, query, or set of records. Every resource in the REST API is identified by a named URI and is accessed with standard HTTP methods (GET, PATCH, DELETE are POST, HEAD).
REST API is based on the resources—their URIs and the relationships between them. You can use it to interact with your Salesforce organization. For example:
- Update or delete records.
- Get a summary of the API versions available to you.
- Run a query or search.
- See comprehensive information about Salesforce objects like a user, account, etc.
- Use compression.
The REST API allows you to apply compression for requests and responses by the standards defined by the HTTP 1.1 specification. Compression is automatically supported by some clients and can be manually added to others.
To apply compression, include the Encoding Accept: gzip or Encoding Accept: deflate HTTP header in the request. The REST API squeezes the response if the client specifies this header correctly. The response contains the header Content-Encoding: gzip or Accept-Encoding: deflate. You can constrict any request by enabling the Content-Encoding: gzip or Content-Encoding: deflate header.
Compressing the Response
The REST API can further constrict responses if the client transmits an Accept-Encoding header. It does not demand that the REST API constrict the response even if you specified Accept-Encoding, but this is usually the case. If the REST API squeezes the response, it specifies the Content-Encoding header.
The REST API unpacks any requests before processing. The client MUST transmit a Content-Encoding HTTP header in the request with the name of the corresponding compression algorithm.
If you are not a member of the Developer Community, register in the Developer Edition organization. If you already have this edition, make sure it enables API permission. Note that these permissions are enabled by default.
It is possible to access the REST API in the Group and Professional versions, but this involves whitelisting the app. The sdfc API is very large. The data is returned as a JSON array, and the granularity returned depends on the SQL query. Parameters are provided as part of the URL. It must enable the SSL endpoint on your app server.
The API utilizes pagination. Each response page contains the URL of the next page. This field is blank if there are no more pages to download.
Working With Postman
To take full advantage of the Salesforce APIs, you need a tool to help you speed up development. For example, Postman is an app for cooperating with the HTTP API. It has an intuitive interface for getting requests and reading responses and robust testing functions. If you want to install it as a plugin, go to the Google Chrome online store, search for Postman, and append it to Chrome.
Stage 1. Creating a Linked App in Salesforce
Salesforce grants a "Connected App" that allows an external system to integrate with Salesforce. It utilizes the standard SAML and OAuth protocols to authenticate single sign-on and give tokens to apply with the Salesforce API.
Open New Connected App and fill:
In the "Basic Information" field:
API Name: that becomes YourAppName.
Connect App Name: YourAppName.
Contact Email: your email address.
In the API part (Enable OAuth Settings):
- Choose the Enable OAuth settings check box.
- Input a callback URL:
This will be the URL to which Salesforce will transmit POST requests when the user has enabled the app to access your data. It will cover the access and request token. Therefore, if you do not already have it, you need to configure an endpoint that should receive and process this request.
In selected OAuth scopes:
- Pick Access and Manage Your Data (API). Press Add. After setting up your app, you will get a Consumer Key and Consumer Secret. Take note of them, as it requires this information to authenticate the external app.
Go to Management-> OAuth Policies-> pick "Remove IP Restrictions".
Stage 2. Salesforce Oauth Basic Data Flow
Data flow works this way. To start, you will be redirected to the Salesforce.com authorization endpoint, where you will log in and confirm access to the data access app. After successful authorization, Salesforce transmits a URLponse with an access token and refresh token.
- The refresh token applies to obtaining a valid access token (if the current access token has expired).
- The access token is passed in the header of all API requests for data and has an expiration date. The default expiration date is fifteen minutes (according to Salesforce session settings).
Creating an Access Token
Salesforce REST API authentication requires an access token. It can get the access token only by the refresh token.
OAuth endpoints in Salesforce:
- Authorization: https://YourInstance.salesforce.com/services/oauth2/authorize
- Token Request: https://YourInstance.salesforce.com/services/oauth2/token
Various components are involved in sending an HTTP request to generate an access token. The “Postman” will be accepted as an API request tool for creating an access token.
Input the base URL like:
https://um2.salesforce.com/services/oauth2/token and pick the HTTP POST method.
Input the key/pair values in the Query Parameters mode of the user interface. It will then append the query parameter and their values to the endpoint URL.
Press Submit and you will receive access_token, instance_url, and token_type. This access token is further worked as a criterion in the header for sending HTTP requests.
The consumer secret (client secret), consumer key (client ID), and refresh token are used to get an access token from Salesforce. Once an access token is received from Salesforce, the customer will pass that Salesforce token on to their next web service calls. When the access token is valid, you can go to Salesforce objects.
Session ID Authorization
If you are not handling someone else's password, you can use the session ID instead of the OAuth 2.0 access token.
Get the session-id like SOAP API. Authorize () call returns session id. You can have a session ID, for instance, as part of the current Apex context.
If the session ID is needed only for testing during development, use the username and password OAuth flow in the cURL command:
You must provide your client ID and secret, username, and password with the added user security token. Use the session ID when submitting a request to the resource. Substitute the identifier for the token value:
Configuring the HTTP Login Request URL
Below is the structure for generating a Request URL for a Salesforce org for Request URL using Base URL + Parameters.
In the above URL, supersede the text with:
- YourConsumerSecret: Retrieved from the connected app.
- SalesforceUserName: User ID in Salesforce.
- YourConsumerKey: Retrieved from the connected app.
- SalesforcePassword: Salesforce login credentials.
Sending HTTP Requests via REST API Resources
The HTTP requests should contain the next information:
- HTTP method.
- OAuth 2.0 access token related to authenticating the request.
- The HTTP ACCEPT header is related to specifying the format of the resource (XML or JSON), or the .json or .xml URI extension. The default uses JSON.
- Lightning Platform REST Resource.
Any JSON or XML files that contain the information required for queries, such as updating a record with new information. HTTP methods are applied to specify the desired action, such as retrieving information and creating, deleting, and updating records.
- HEAD - to retrieve resource metadata.
- GET - to get information, such as a summary of the underlying resources.
- POST - to make a new object.
- PATCH - to update a record.
- DELETE - to delete a record.
To access a resource, transmit an HTTP request comprising the header, method, and name of the resource.
When to Take the Apex REST API
This is done when you need to provide Apex classes and methods so that external systems can access code throughout the REST architecture. The Salesforce Apex REST API integration keeps up both OAuth 2.0 and a session ID for authorization. It utilizes the same underlying data model and standard objects as the SOAP API and follows the same constraints.
Stage 3. Basic REST API Salesforce Sample Code
Now we show a simple REST API in Apex with HTTP request methods for retrieving, deleting, or updating a record.
- Build an Apex class in your instance from the installer. Enter Apex Classes in the Quick Find box, choose Apex Classes, and press New.
- Append this code to your new Apex class.
- To call of a customer and get an account by ID, in a command prompt window, enter the next cURL command:
Supersede sessionId with the element you marked in the login response.
The instance with your ; element.
AccountId with the identifier of an account that exists in your organization.
Upon calling the Get Method, Salesforce refunds a JSON response with the next data:
Create an account.txt file comprising the credentials for the account you will make in the next step.
In a command prompt window, run the following cURL command to make a new account:
Subsequent to calling doPost, Salesforce refunds a response with data in the form of:
ACCOUNTID is the ID just created with the account POST request.
In a command prompt window, run the following cURL command to remove the account with the ID:
Authenticating Your Request via Salesforce
Generate a POST method and replicate the request URL as shown below. Press submit.
On successful login, you will get the instance URL, access token type. This access token is then utilized as a parameter value in the header to transmit any HTTP requests and receive a response from Salesforce.
Stage 4. Retrieving Record Details From Salesforce
Now you need to get detailed information about the record of the Salesforce object with GET. Below is a sample URL.
https: // instanceurl /services/data/v25.0/sobjects/ Object Name / Identifier
In this URL, supersede the highlighted text with
Instanceurl: Instanceurl obtained in the same way.
Object Name: SObject objects like Account, Contact, Lead, etc.
Id: This is the ID of the sales department of the specific SO object record you selected.
Generate a GET method, copy the URL and access token, the token type in the header sector, and press submit. In response, you will receive all the account details for that record.
Creating a Salesforce Record by REST
Now let's see how to append records to a Salesforce object by applying the POST method. Below is a sample URL.
https: // instanceurl /services/data/v25.0/sobjects/ Object name
In the above URL, substitute the highlighted text with
Instanceurl: Instanceurl obtained in the same way as above.
Object Name: SObject objects in the form of Lead, Contact, Account, etc.
Using a POST method, copy the access token and URL to the header sector. Specify the record information in XML or JSON format. Press submit. In response, you will receive the SalesforceId of the record if it successfully added the record to the Salesforce org; otherwise, you will receive an error message.
What Are Salesforce Objects?
These objects (also called sobjects) are database tables that contain organization data. The default is Leads, Accounts, Contacts, and Tasks. You have the option of making your custom objects. Keep in mind that every time you make a new sObject in Salesforce, it automatically becomes available in the API.
A Salesforce record describes a particular occurrence of an object. The underlying comparison in a database table will be like a row.
Integration via Third-Party Connectors
It's important to highlight the difference between integrating the Salesforce API and Salesforce apps with AppExchange or other third-party connectors. AppExchange apps — for example, API Integration Utility — give you the ability to embed your solution into the Salesforce platform. But this comes with certain costs, as well as the use of third-party connectors.
API Salesforce integration is much simpler and focused primarily on sending data from your app and receiving data from Salesforce. Currently, this type of integration does not demand additional costs.
API Custom Development With Zapier
Zapier is a convenient service, though not the only one, that allows you to set up complex integrations between solutions and automate workflows. The process using the Zapier platform differs from other solutions. Instead of a complete application for each part of the API, Zapier is a collection of the most important API functions.
Integration with Zapier starts with authentication, carefully selected API functions, and forms.
Determine how your application authenticates users. Most apps demand authentication, from API keys or passwords to OAuth login flows. When creating the integration, tell Zapier how to authenticate users of your apps. Install this once and Zapier will use the same authentication scheme for every API call it makes. It's the same with users: After authenticating your app with Zapier, they can use any of its triggers and actions without re-authentication (unless they want to append a second account).
Pick the parts of your API that are most important to make Zap steps, including actions and triggers. Anything you need to search for existing data, track, or append new data will do. Find out which ones are most important and best suited for automated workflows, and list the API calls and required inputs.
Highlight what data your app outputs that users will most often use in other stages of Zap. Triggers rarely need additional detail—an API call is enough to get the freshest data from the app, and you only need more information to filter out that new data. This requires a form. Inside Zapier, customers always see a form to fill in data with either plain text or the displayed input fields from the preceding steps.
The demands of the modern world are transforming, and flexibility has become a key business requirement. Today's customers want to interact with each other across different channels and on different devices. Employing Salesforce CRM API integration allows the user to easily search, view, and modify data collected outside the Salesforce organization in the Salesforce interface, providing a 360-degree customer view.
Integration and customization are not as easy if you do not have the experience and the authority. However, this is not a problem — you can use the services of a professional Salesforce developer to customize the API integration according to your business process.
This is what the Ergonized team offers. Find out how we tie together disparate systems and optimize your IT infrastructure through API Salesforce integration. Contact us to learn all about how to use the Salesforce API.