We need to run the axios.post equivalent for following cURL command in nodeJS:
curl -H "Authorization: Basic ZjM4Zj...Y0MzE=" -d grant_type=refresh_token -d refresh_token=NgAagA...NUm_SHo https://accounts.spotify.com/api/token
My Approach:
axios.post("https://accounts.spotify.com/api/token", {
grant_type: 'refresh_token',
refresh_token: 'NgAagA...NUm_SHo',
header: {
Authorization: 'Basic ZjM4Zj...Y0MzE=',
}
}).then((resAxios) => {
console.log(resAxios.data)
spotifyResult = resAxios.data;
}).catch((error) => {
console.error(error)
})
Above code returns the following error in reponse:
statusCode: 415,
statusMessage: 'Unsupported Media Type'
Format:
refresh_token
should be application/x-www-form-urlencoded
Authorization: Basic <base64 encoded client_id:client_secret>
Refer the 'Authorization Code Flow' for the cURL command, here:
https://developer.spotify.com/documentation/general/guides/authorization-guide/
Feel free to provide with any other variant, i.e., instead of using axios. I preferred it, since it parses the fetched data as well. Please provide with the code to parse it with, if so. I'm a 'beginner' beginner.