0
votes

In Google scripts, I am attempting to call the client_credentials OAuth flow from spotify, while it should return the access token, the request fails with code 405.

data = {
    'grant_type':'client_credentials',
    'client_id' : 'CLIENT_ID',
    'client_secret' : 'CLIENT_SECRET'
}
var access_token= UrlFetchApp.fetch('https://accounts.spotify.com/api/token', data);

More on spotify OAUTH https://developer.spotify.com/web-api/authorization-guide/#client-credentials-flow

1

1 Answers

0
votes

Your request isn't formatted correctly. If you look closer at the documentation, you'll see that it is only the grant_type that should be sent as a request body parameter.

The Client ID and Secret should be sent as a header parameter. The parameter name should be Authorization and the parameter value should be Basic [base_64_encoded_value_of(client_id:client_secret)]