March 2nd, 2025
Spotify provides API resources specifically for developers to create any kind of application using the endpoints they created. However, it is limited for test users at first and you'll have to submit for extension request. Here is a brief tutorial on how to utilize the API as well as the whole process of submission.
Have you ever wondered how they make Spotify last month receipt and other data manipulation? Nowadays, there are plenty applications that use Spotify Web API. Developers can access the Spotify official API through the documentation provided by Spotify here. However, it is limited for test users at first and you'll have to submit for extension request. Spotify already has its own documentation which has a very well structured and complete steps on how to utilize this API and the requirements, but if you're not a person who has a lot of time you can save up your time by reading this article.
Before we begin, make sure you have the following:
To use the Spotify API, you need to register your app:
Spotify uses OAuth 2.0 for authentication. You'll need an access token to make API requests.
Spotify offers two authentication flows: Authorization Code Flow (for user-based actions) and Client Credentials Flow (for app-only access).
For web applications, use the Authorization Code Flow:
https://accounts.spotify.com/authorize?
client_id=YOUR_CLIENT_ID&
response_type=code&
redirect_uri=YOUR_REDIRECT_URI&
scope=user-read-private user-read-emailExchange this code for an access token by making a POST request:
fetch('https://accounts.spotify.com/api/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + btoa(CLIENT_ID + ':' + CLIENT_SECRET)
},
body: new URLSearchParams({
grant_type: 'authorization_code',
code: AUTH_CODE,
redirect_uri: REDIRECT_URI
})
}).then(response => response.json())
.then(data => console.log(data.access_token));
The btoa function encodes data into Base64, which is required for Spotify’s Basic Authorization. If you're using PowerShell, you can generate the required string like this:
$clientId = "YOUR_CLIENT_ID"
$clientSecret = "YOUR_CLIENT_SECRET"
$authHeader = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$clientId`:$clientSecret"))
Write-Output $authHeaderFor an easier method, you can use Postman or an extension in Visual Studio Code called Thunder Client. Use the POST method to send a request to the following URL:
https://accounts.spotify.com/api/tokenIn the Authorization tab, select Basic Auth and enter your Client ID as the username and Client Secret as the password.
In the Body tab, select x-www-form-urlencoded and include the following key-value pairs:
grant_type: client_credentialsClick Send, and you will receive an access token in the response.
Once you have the access token, you can use it to make API requests. The data you can get from API are various, the complete examples are in the documentation. Do not forget to put any token or important credential in the .env file in your application.
fetch('https://api.spotify.com/v1/me', {
headers: {
'Authorization': 'Bearer ' + ACCESS_TOKEN
}
})
.then(response => response.json())
.then(data => console.log(data));fetch('https://api.spotify.com/v1/search?q=Imagine Dragons&type=track', {
headers: {
'Authorization': 'Bearer ' + ACCESS_TOKEN
}
})
.then(response => response.json())
.then(data => console.log(data.tracks.items));
Now that you can fetch data from Spotify, you can integrate it into your web application. If you're using React, store the access token in state or context, and use hooks to fetch data.
import { useEffect, useState } from 'react';
function SpotifyTracks({ accessToken }) {
const [tracks, setTracks] = useState([]);
useEffect(() => {
fetch('https://api.spotify.com/v1/search?q=Imagine Dragons&type=track', {
headers: {
'Authorization': 'Bearer ' + accessToken
}
})
.then(res => res.json())
.then(data => setTracks(data.tracks.items));
}, [accessToken]);
return (
{tracks.map(track
{track.name} by {track.artists.map(a => a.name).join(', ')}
))}
);
}With Spotify's Web Playback SDK, you can control music playback directly from your web app.
const player = new Spotify.Player({
name: 'My Spotify Player',
getOAuthToken: cb => { cb(ACCESS_TOKEN); }
});
player.connect();Now your application is done, you can always use any endpoints as much as you like and modify your code to your own preference.
Despite your application is done and works perfect, you need to do quota extension request to the Spotify so your app is no longer in development mode. If your app is still in development mode, it only works in your account if you haven't add other test users. Even though in development mode, you can still access your app using any device and IP but is still limited to your Spotify account. To allow other people, you can add them as the test users in the User Management section in the Spotify Developer Dashboard. In my case, my app needs to be accessible to public so I submitted a quota extension.
Without this approval, your app will be restricted to your Spotify Developer Account, meaning only you can log in and use the API features.
Design guideline is one of things you must pay attention in to get approved by Spotify for quota extension. Spotify already provides the complete design guideline but I'll summarized them to you:
The Spotify API allows developers to integrate music features into their applications, from searching for songs to controlling playback. It is one thing to consume their API, but the most crucial thing is in the Quota Extension Request if you intend to make your app public. With these tips, you may be able to utilize the Spotify API and pass the quota extension request.