Refresh Access Tokens

Refresh your access tokens if they have expired.

Client credential access token

Click the "Run" button to generate a new client credential access token.

Press + to interact
const endpointUrl = new URL('https://accounts.spotify.com/api/token');
const queryParameters = new URLSearchParams({
grant_type: 'client_credentials'
});
const required_ids = Buffer.from('{{CLIENT_ID}}:{{CLIENT_SECRET}}');
const encoded = required_ids.toString('base64');
headerParameters = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic '+encoded
}
const options = {
method: 'POST',
headers: headerParameters
};
async function fetchAccessToken() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
fetchAccessToken();

Authorization code access token

Use the code below to generate an authorization code access token using a refresh token.

Press + to interact
const endpointUrl = new URL('https://accounts.spotify.com/api/token');
const queryParameters = new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: '{{REFRESH_TOKEN}}'
});
const required_ids = Buffer.from('{{CLIENT_ID}}:{{CLIENT_SECRET}}');
const encoded = required_ids.toString('base64');
headerParameters = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic '+encoded
}
const options = {
method: 'POST',
headers: headerParameters
};
async function refreshAccessToken() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
refreshAccessToken();