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:
To pull data from the Spotify API to Google Sheets easily and without writing any code, first install and open the Apipheny Google Sheets add-on.
Apipheny is a no-code API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs (including the Spotify API), save API requests, schedule API requests, and more. Click here if you want to learn more about Apipheny.
1. Install Apipheny by clicking the Install button on this page.
2. After you’ve installed Apipheny, open a Google Sheet and then click on the Add-Ons option in the top menu. In the add-ons menu, you should see Apipheny.
Click Apipheny > Import API to open the Apipheny sidebar in your Google Sheets.
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. Do not include the carrots “<>”.
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:
After you authorize the app, you’ll then see your “Code” in the URL/address bar.
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 console window and enter in the following command:
curl -d grant_type=authorization_code -d code=<code> -d redirect_uri=<redirect_URI> -d client_id=<client_id> -d client_secret=<client_secret> https://accounts.spotify.com/api/token
Don’t forget to replace the values between brackets (code, redirect_URI, client_id and client_secret) with their actual values. These are the same values you’ve obtained in previous steps. Do not include the carrots “<>” around any of the values.
After running the command, your access token will then be displayed in the response:
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 (JSON / CSV), 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 where it says “API URL”.
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>
Just copy and paste “Authorization” into Apipheny, where it says “Key”. And copy and paste Bearer <your_token> into Apipheny, where is says “Value”. But make sure to replace <your_token> with the same value of the token that you generated previously, in Step 5. Do not include the carrots “<>” around your token, but do leave a space between “Bearer” and your token in the “Value” field.
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, such as:
Related articles:
Meelad Mashaw