Spotify is one of the most popular music streaming platforms in the world.
In this tutorial, I’ll show you how to connect the Spotify REST API to Google Sheets in 8 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
Next, make sure you’re logged in to your Spotify developer account.
Then, in your Spotify developer account’s Dashboard, click the Create an App button:
Complete the App name and description fields, check the two checkboxes, and then click the Create button:
Your app will then be created. Under the app name, you should see the “client id”. Under it, click the Show Client Secret link to display the client secret:
Copy and paste the values of both your Client ID and Client Secret to a safe location, because you will need them in the next steps.
After you’ve created the app, click the Edit Settings button in your Developer account:
In the Edit Settings section, complete the Redirect URIs field then click the Add button:
The redirect URI is now added:
Click the Save button to complete this step:
In your internet browser’s address/URL bar, copy and paste the following link:
https://accounts.spotify.com/authorize?client_id=your_client_id&response_type=code&redirect_uri=https://apipheny.io/&scope=user-read-private%20user-read-email&state=34fFs29kd09
Make sure to replace the your_client_id parameter with your client id from Step 2.
After copying and pasting the URL into your browser, and clicking Enter, you will be prompted to log in to your Spotify platform account.
After logging in, the browser will then redirect and display a dedicated authorization page:
Copy and paste the code value somewhere safe, because you’ll need it in the next steps.
To get your API access token, open a command prompt window for Windows OS or a terminal for Mac OS and enter in the following command:
curl -d grant_type=authorization_code -d code=your_code -d redirect_uri=your_redirect_URI -d client_id=your_client_id -d client_secret=your_client_secret https://accounts.spotify.com/api/token
Note: For Mac OS you may need to use single quotes ( ' ) instead of double quotes ( " ).
Don’t forget to replace the values for your_code, your_redirect_URI, your_client_id and your_client_secret with their actual values. These are the same values you’ve obtained in previous steps.
After running the command, your access token will then be displayed in the response:
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 Spotify API documentation to find an API endpoint URL that retrieves the information you need. If you already know your URL, or you want to use the same example URL as us, just skip to Step 7.
First, open the Spotify API documentation page: https://developer.spotify.com/documentation/web-api/reference/
The menu on the left contains a list of categories for the Spotify API endpoints:
If you click on an API category, for example Artists, a list of that category’s endpoints will be displayed:
An example endpoint is the Get Several Artists endpoint from the Artists category, which returns Spotify catalog information for several artists, based on their Spotify IDs. The URL for this endpoint is:
https://api.spotify.com/v1/artists
Each endpoint’s documentation contains a descriptive title, a paragraph describing the endpoint’s purpose, a table with the required headers and parameters, followed by a response format section. In a distinct section on the right, you will see the endpoint’s HTTP method (GET) and URL:
Now, to get your Spotify data in your Google Sheet, go back to your Google Sheet and make sure that you’ve installed the Apipheny add-on and you have it opened to the Import tab. In the Import Tab of Apipheny, enter the following details into the add-on:
Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your Spotify API endpoint. For this example, we are using the “GET” method.
API URL: In Step 6, we explained how you can find the Spotify API endpoint that you need. Now copy your complete Spotify API URL into the Apipheny add-on, in the field that says API URL Path, followed by any GET parameters required for your query (if applicable).
For this example, we are using the Get a List of New Releases endpoint that returns a list of new releases. The URL for this specific endpoint is:
https://api.spotify.com/v1/browse/new-releases
If you’re following the same example as us, just copy and paste the above URL into Apipheny.
Headers: In the Headers section of the Apipheny add-on, add one row with the following key and value:
Header Key: Authorization Value: Bearer your_token
Make sure to replace your_token with the same value of the token that you generated previously, in Step 5. Leave a space between Bearer and your_token.
Here’s what your Spotify API should look like when entered into Apipheny, if you’re following the same example as us:
The last step is to click the Run button at the bottom of the Apipheny add-on and then your Spotify data will be imported into your Google Sheets. Congratulations!
After making a successful request to the Spotify API, try querying a different Spotify API endpoint, or try using one of the more advanced features in the Apipheny add-on.
Crypto API tutorials and more:
Sponsored by Zink Virtual Tip Jar & Rewording.io Paraphrasing Tool
Accept donations on Twitch | Accept donations on Discord | Accept donations on YouTube | Accept donations on Telegram | Accept donations on Twitter | Accept donations on TikTok | Accept donations on Instagram | Accept donations on LinkedIn | Accept donations on Facebook | Accept donations on your Website