Account prerequisites
The Spotify Ads API uses OAuth for authentication and access. Your API client will need an access token and secret before making API calls. Make sure you have the following before proceeding:
- A valid Spotify account depending on your usage (e.g. personal development, work, etc.).
- A valid Ad Studio account.
Initialize your new Spotify Ads API application
Setting up your Ads API app is a one-time process. Follow these steps to get started:
Create an application at developer.spotify.com to get a client ID and client secret (check out the App Settings page for a bit more on this). The client ID will be referred to as
<CLIENT_ID>
in further steps below.Configure a redirect URI for the application (e.g.,
http://localhost:8080/callback
). This will be referred to as<REDIRECT_URI>
in further steps below.Accept the API Terms with your client ID in Ad Studio.
* Conditional * If you require access to Campaign Management capabilities, please fill in the pre-integration questionnaire here and the Spotify Ads API team will review your request within 3-5 business days. Skip this step if you only need access to Reporting capabilities.
* Conditional * If you intend to onboard more than 25 users onto your app, please submit a quota extension request via the Developer Dashboard. Once you have submitted the request, a dedicated team at Spotify will review all the provided information and get back to you within 6 weeks.
Authenticate your Spotify Ad Studio account
Account authentication is the next step after you set up your application. Follow these steps to get started:
In a web browser, copy the URL below into the address bar. Replace your client ID and properly escaped redirect URI with the values you registered with the app.
https://accounts.spotify.com/authorize/?client_id=<CLIENT_ID>&response_type=code&redirect_uri=<REDIRECT_URI>
I.e., concretely, in the URL, replace:
<CLIENT_ID>
with your client ID.<REDIRECT_URI>
with your callback URL.
After you replace the values, navigate to that URL
Log in your Spotify account and authorize your application. Clicking Login returns a 404 error, but that’s ok.
Check the browser address bar for the parameter
code=XXXXXXXX
. The Xs are placeholders for your access code. The access code is valid for 10 minutes. Save the code for Step 5.Open a terminal window and run the command shown below. In this command, replace
<CLIENT_ID>
and<CLIENT_SECRET>
with your real client ID and secret. Save the output for Step 5.echo -n <CLIENT_ID>:<CLIENT_SECRET> | base64
Run the command shown below to generate an access token. A valid token is required to make API requests.
In this command, replace:
<BASE64_OUTPUT_FROM_STEP_4>
with the code from Step 4.<CODE_FROM_STEP_3>
with the code from Step 3.<REDIRECT_URI>
(afterredirect_uri=
) with your callback URL.
Authentication results
You should now see a response that looks similar to this:
{
"access_token": "XXXXXXXXXXXXX",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "XXXXXXXXXXXX",
"scope": ""
}
The access (bearer) token give you access to the API endpoints for 1 hour. Save the refresh token in a safe place.
Using the refresh token
Your refresh token is used to request new, short lived access tokens.
Run the following command in a terminal window when you need to renew API access with your refresh token:
curl -H "Authorization: Basic <BASE64_OUTPUT_FROM_STEP_4>" \
-d grant_type=authorization_code \
-d code=<CODE_FROM_STEP_3> \
-d redirect_uri=<REDIRECT_URI> \
https://accounts.spotify.com/api/token
In this command, replace:
<BASE64_OUTPUT_FROM_STEP_4>
with the output from Step 4 above.<REFRESH_TOKEN_FROM_RESULTS>
with the value of the refresh token returned by the response shown in the Authentication Results section above.
Getting Account IDs
The refresh operation above outputs a new short-lived access token, which you can now use to make API requests as shown below:
curl --request GET \
--url https://api-partner.spotify.com/ads/v1.4/currentUser/adAccounts \
--header 'Authorization: Bearer <ACCESS_TOKEN>'
You might also be interested in…
Connect Spotify Ads to Tableau
Spotify Ads Looker Studio Connector
Connect Spotify Ads to Snowflake
Connect Spotify Ads to Google BigQuery
Connect Spotify Ads to Power BI
How to Connect Google Sheets data in BigQuery
Power BI BigQuery Connection in 2023
Easily Connect BigQuery to Excel in 2023