How to Build a Basic Salesforce REST API Integration

Due to the large reach of Salesforce, there is a big opportunity to leverage their ecosystem if you have a product in the sales and marketing space. A recent tutorial by Russell Vaughan of GoSquared does just this by showing you how to build an integration with the Salesforce API Track this APIto send marketing insights to a sales team.

What the REST API does for you is to capture users’ (or leads) behavior when they browse a site. When a lead takes a look at your pricing page or views a webinar, your sales team can follow up with a workflow created in Salesforce. When you build the app based on these benefits (and the steps included in the original article), you will see how to send customers’ data to Salesforce and how to retrieve customers’ data from Salesforce.

Vaughan makes clear that a connected app should be thought of as a small app that sits on Salesforce’s infrastructure and it is where the integration takes place. The connected app can help you to authenticate and redirect requests to a client. After setting up your Salesforce developer account, the tutorial takes you through the steps to set up a connected app. Once you have your app, you’ll be given a Consumer Key and a Consumer Secret.

Next the tutorial looks at how to implement the features starting with authorization.

1.Salesforce Oauth data flow

Since you need customer data, you will invite users to go to your website to make actions (click, watch, scroll, browse, etc). Once your customers’ data is recorded, it will be redirected to a Salesforce.com auth endpoint and you will have access granted through an endpoint. The idea is to transfer their Salesforce data on their behalf.

After a successful authentication with an endpoint, Salesforce will send a response with an Access and Refresh token. The Access token has an expiration date of 15 minutes and the Refresh token helps you get in when the Access is expired.

That’s the request you will make as an initial authorization. The client_id will be your consumer ID from the connected app and the redirect_uri will be the Callback URL. When you have a successful response, your user will login and authenticate.

Once the data is authorized, Salesforce will add an authorization code to the URL, creating a request that looks like this:

With the request and responses, you’re building a base for the next API calls via URL. Because you want to access users’ data on their behalf, you can make requests and receive responses in return, considering the Refresh token that will keep you authenticated.

As you’re an authenticated developer, you will be able to make requests and receive responses (with users’ data behavior for the sales team). You will be ready then, to work with Salesforce objects or sobjects, database tables that include an organization’s data such as accounts, contacts, leads, and tasks.

To illustrate a Salesforce sobject, the author plays with “Johnny Appleseed” a contact object.

2.Push data from your app to Salesforce

To create a contact, build the API URL using the instance from the Access token like this:

(Your contact will need a last name as the minimum for an entry to be created).
The response you get back will be the id of your contact

{"id":"0031r000029NDckAAG","success":true,"errors":[]}

Which will also let you build a link directly to the contact.

https://INSTANCE.salesforce.com/0031r000029NDckAAG

3.Retrieving data from Salesforce to your app

Once you know how to create a contact, you’re ready to retrieve a list of contacts with their respective data by making a request to a describe endpoint as the author recommends, aiming to access fields to be populated by users’ data: