DEV Community

Vikas Arora
Vikas Arora

Posted on

How to Build a Salesforce REST API Integration?

An API based on REST uses HTTP to make requests for functioning with data. REST uses very less bandwidth and hence more preferable for internet usage. API is the aptest code through which two different software programs can communicate with each other.

Uses of REST API

A company which has products in the sales and marketing area, building a Salesforce API can board huge benefits due to the large reach of Salesforce. Listing your product or app on a Salesforce ecosystem is a most tuned community in sales approaches. When a company attains a certain level in terms of strength and size, it finds it suitable to turn to Salesforce for making it big in Sales and marketing. Salesforce has an excellent community of developers and has a well-written solution to almost any obstacle which you are likely to face. In addition, they also have a sound e-learning platform which offers a huge choice of subjects to gain insights on various kinds of terminology and principals.

Building a REST API Integration

A REST API is mainly centered on finding data from the Salesforce against the data which was sent from your product or application. No costs are usually involved in these integrations but you should remember that integrations via REST are only accessible to users of Salesforce on their enterprise plans. The Integration will need 3 vital steps:

Authorization
Data push by User
Data retrieval by User

*Step One: Creating a Developer Account *

They are really useful and offer a Salesforce organization where you can get hands-on with the interface. You also have the leeway to both add and delete users.

Step Two: Connecting an App

Once the developer account is in place, you will have to set up a Connected App which has huge functionality and thus make it difficult to comprehend. To make things simpler, take your connected app as a small application which rests on the infrastructure of the Salesforce which needs to be integrated. This Connected App will cater to the management of the authentication and also channelizing the requests to the proper client services. Thus, now you have to click on Setup icon which is found on the top-right part of the navigation bar. In the Quick Find box, you need to select the App Manager where you have to click the ‘New Connected App’. This will take you to the Basic Information section where you will have to enter three things as follows:

Connect App Name
API Name
Email address

Next, in the API section, after you check on Enable OAuth settings, you have to enter the Callback URL. Latter is the URL, which will be used by Salesforce to POST once the user has permitted your app to have access to his/her data. Thus, this includes the access and request token. You should have a properly defined role for someone to handle and the same. Also, under the Selected OAuth Scopes, select the Access and Manage your data and finally click on Add. A Consumer Key will now be generated in addition to a Consumer Secret for your app.

After the setup, the users are taken to an endpoint for Salesforce authorization where they are required to login and give their approval for the app for accessing the data. Once the authorization is complete, two tokens are sent by Salesforce, namely

**Access Token:** This needs to be put in the header of every API request for data. It has an expiry date and by default, it expires after 15 minutes in Connected Apps.
**Refresh Token:** This is used to fetch a valid access token. Expiry settings can be changed on this.

You have to build the API URL from the Access token response and use the value of the Access token as the bearer token in the header. You have to be careful about the characters that have to be escaped in the access token.

Step Three: Retrieval of data to the app from Salesforce

Before moving to the retrieval you should know about what is meant by the Salesforce objects. Objects of the Salesforce are the database tables which have the organization’s data. These are Accounts, Leads, Tasks, Contacts etc. Custom objects can also be created. A particular occurrence of an object is described by a Salesforce record.

Coming to retrieval, this can be done by making a request to the contact endpoint which will return information about the object under question. Also, you can use a combination of objects ‘describe’ endpoint which will give all the fields which can be populated by the users. Thus, access to all fields can also be used for building a custom query which can give all the associated properties about the object.

Conclusion

Salesforce REST API is easy to work with, has simple integration and simple HTTP requests. Salesforce has shown remarkable success in the enterprise customer level which cannot be countered. It is a perfect choice of technology which can be used with mobile applications and Web 2.0 projects. Salesforce coding skills and REST API is also important and of great use for various web or mobile applications which do not have any basic need for accessing a huge amount of data. It is a pathbreaking platform which is witnessing a significant adoption rate. This has also boosted the career opportunities for the ones who have proper Salesforce Online Training.

Top comments (0)