Pinterest is a social network that allows users to visually share and discover new interests. We can use the Pinterest API to import data from Pinterest into Google Sheets. In this tutorial, we’ll show you how to connect the Pinterest REST API to Google Sheets in 6 steps:
Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.
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
After logging into your Pinterest Business account, go to https://developers.pinterest.com/apps/ and connect an application by clicking the Connect app button:
Complete all the fields that appear on the screen:
Mark the I’m not a robot checkbox, then click the Submit button:
After creating the app, your trial access will be in the Pending status. To become Active (as shown in the picture below) you may need to wait a couple of days. After the status is Active you can proceed with the next steps.
After your app has been approved, in the Configure tab you will find your App id and App secret key:
Copy these values to a safe location because you will need them later.
In your browser’s URL bar, paste the following link and then press Enter:
https://www.pinterest.com/oauth/?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&scope=boards:read,pins:read,ads:write,boards:writepins:write,user_accounts:read&state=abc
When you visit the URL, an Authorization page will then be displayed. Click the Give access button to continue:
The browser will then navigate to the redirect URL that you provided when you registered your client. One additional query parameter (a code) will be added to your browser’s address bar, at the end of the redirect URL. The code parameter is a single use login code that we will now use to acquire an access token:
Open up a command prompt window (for Windows OS) or a terminal (for Mac OS) and compose the following curl command:
curl -X POST https://api.pinterest.com/v5/oauth/token --header "Authorization: Basic ENCODED_STRING" --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "grant_type=authorization_code" --data-urlencode "code=YOUR_CODE" --data-urlencode "redirect_uri=REDIRECT_URI"
You’ll need to replace a few values:
client_id:client_secret
. client_id is your app_id and client_secret is the app secret key. You can use a site you trust such as https://www.base64encode.org/ to encode them.Note: For Mac OS, you may need to use single quotes ( ‘ ) instead of double quotes ( ” )
Our request entered in the command prompt window:
In the response that you get back, your access token will be displayed.
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 Pinterest API documentation to find the endpoint that retrieves the data you need from Pinterest. If you already know your API URL, or you want to use the same example URL as us, just skip to Step 5.
First, open the Pinterest API documentation page: https://developers.pinterest.com/docs/api/v5/
The menu on the left contains general information about the Pinterest API and a list of categorized endpoints.
If we click the Pins category, a list of its endpoints will be displayed:
An example endpoint is Get Pin, which returns a pin owned by the operation user_account, or present on a group board that has been shared with this account:
https://api.pinterest.com/v5/pins/pin_id
If you use this URL don’t forget to replace pin_id with your own value!
The endpoint’s documentation contains a short description of the endpoint’s purpose, its HTTP method (GET), the URI, the path parameters, the query parameters, the cURL command and example responses:
All API calls to Pinterest should be made to this base URL: https://api.pinterest.com/v5/
The List feeds endpoint, which fetch feeds owned by the “operation user_account”:
Method: GET API URL Path: https://api.pinterest.com/v5/catalogs/feeds Headers: Header 1 Key: Content-Type Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained.
The List products endpoint, which gets a list of product pins for a given Catalogs Product Group Id owned by the “operation user_account”:
Method: GET API URL Path: https://api.pinterest.com/v5/catalogs/product_groups/{product_group_id}/products Headers: Header 1 Key: Content-Type Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained and {product_group_id} with a valid product group ID.
The Get customer lists endpoint, which get a set of customer lists including id and name based on the filters provided:
Method: GET API URL Path: https://api.pinterest.com/v5/ad_accounts/{ad_account_id}/customer_lists Headers: Header 1 Key: Content-Type Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained and {ad_account_id} with a valid add account ID.
The List Pins endpoint, which gets a list of the Pins owned by the “operation user_account”:
Method: GET API URL Path: https://api.pinterest.com/v5/pins Headers: Header 1 Key: Content-Type Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained.
Pagination is a process that is used to divide a large dataset into smaller chunks (pages). Usually the endpoints that return a list of resources support pagination.
Some of the Pinterest API endpoints that return a list or an array support pagination. This means you need to add some of these parameters at the end of the URL:
Example: https://api.pinterest.com/v5/boards/{board_id}/pins/?page_size=100
The example above, return 100 Pins from a board, using List Pins on board endpoint and the page_size query parameter is set to 100.
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, POST, PUT, etc) 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 Pinterest REST API endpoint that you need. Now copy and paste your complete Pinterest 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 List boards endpoint, which get a list of the boards owned by the operation user_account + the group boards where this account is a collaborator. This is what the whole URL looks like:
https://api.pinterest.com/v5/boards
Headers: In the Headers section of Apipheny, add two rows with the following keys and values:
Header 1 Key: Content-Type Value: application/json Header 2 Key: Authorization Value: Bearer your_token
In header 2’s value, make sure to replace your_token with the value of the API key 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 Pinterest API data to be imported into your Google Sheet. Here’s what our request looked like when completed:
Crypto API Tutorials: