Salesforce is one of the world’s most popular customer relationship management platforms. In this tutorial, we’ll show you how to connect the Salesforce REST API to Google Sheets in 6 steps:
Apipheny is a free API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to API data sources, easily.
1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install
2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.
In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
4. Choose the scopes you want to use:
5. Click the Save button to finally create the app:
6. Change the IP Relaxation Setting:
Go to Apps = > App Manager and find your app. Click the corresponding arrow and choose Manage from the drop-down menu:
Click the Edit Policies button:
Change the IP Relaxation setting to Relax IP restrictions:
Open up a command prompt window (for Windows OS) or a terminal (for Mac OS) and write the command below to obtain a token:
curl -s -X POST -F grant_type=password -F client_id=YOUR_CLIENT_ID -F client_secret=YOUR_CLIENT_SECRET -F username=YOUR_USERNAME -F password=YOUR_PASSWORD https://login.salesforce.com/services/oauth2/token
You’ll need to fill in a few parts:
Note: For Mac OS you may need to use single quotes ( ' ) instead of double quotes ( " ).
Executing this command will return your access token in the response:
Copy and paste your new token to safe place because you’ll need it in the next steps.
Note: If the token/key that you generate has an expiration time, you will need to complete this same process again to get a new token when the old one expires.
In this section, we’ll show you how to browse the Salesforce API documentation to find the Salesforce API URL that retrieves the information you need from your Salesforce account. If you already know your URL, or you want to use the same example URL as us, just skip to Step 5.
First, open the Salesforce API documentation page: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_list.htm
The main part pf the page contains the basic URL that you should use, a table containing the endpoints, and a short description for each endpoint:
An example endpoint is Resources by Version, that lists available resources for the specified API version, including resource name and URI. This is the corresponding URL for that endpoint:
https://yourInstance.salesforce.com/services/data/v54.0/
If you use this URL, don’t forget to replace yourInstance with your domain name.
The documentation for each endpoint contains a short description of the endpoint’s purpose, the URI, the response format (JSON, XML), the endpoint’s HTTP method (GET), the authentication method, and a list of the accepted API parameters:
Note: Salesforce changes the version of their API often. Check their documentation to confirm the latest version and update the version number in the URL if necessary.
Now go back to your Google Sheet and make sure that the Apipheny add-on is open on the “Import” tab. With the Import tab open, enter these details into the add-on:
Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.
API URL: In Step 4, we explained how you can find the Salesforce REST API endpoint that you need. Now copy and paste your complete Salesforce API URL into the Apipheny add-on, where it says API URL Path, followed by any parameters required for your query (if applicable).
For this example, we are using the Account Info endpoint, that retrieves basic information about an Account object. This is what the whole URL looks like:
https://YOUR_INSTANCE.salesforce.com/services/data/v54.0/sobjects/Account/
If you’re following this same example as us, just replace YOUR_INSTANCE with the domain you are using.
Headers: In the Headers section of the Apipheny add-on, add two API header rows with the following keys and values (if you’re following the same example as us):
Header 1 Key: Authorization Value: Bearer your_token Header 2 Key: X-PrettyPrint Value: 1
Don’t forget to replace your_token with the value of the token you obtained previously, in Step 3. There should be a literal space between Bearer and your_token.
Finally, the last step is to click the Run button at the bottom of the Apipheny add-on and then wait for the Salesforce API data to be imported into your Google Sheet.
After making a successful request to the Salesforce API, try querying a different Salesforce API endpoint, or try using one of the more advanced features in the Apipheny add-on, such as:
Schedule requests for automatic updates
Reference cell values in requests
Stack multiple URLs in a single request
Crypto API Tutorials: