Reputation: 13
I'm using jscript with the Spotify Web Api to make an app. I'm using the request module to call from app.js on node.js, I've managed to make it play once the player has been paused, however it won't load the context_uri or from the uris array. I've tried every type of formatting for the json as possible and can't get it to play a chosen track or album. Here's my code:
request({
method: 'PUT',
uri: 'https://api.spotify.com/v1/me/player/play',
headers:{
Authorization: 'Bearer ' + access_token
},
data:{
"context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr"
}
}, function (error, response, body) {
console.log(body);
});
So I don't get any errors upon sending the request, however it's not changing the current song on the player to the song sent in the context_uri. I'm not sure weather my formatting is wrong or it's something else but I'd appreciate the help, thanks.
Upvotes: 1
Views: 1866
Reputation: 1421
Try this:
var options = {
url: 'https://api.spotify.com/v1/me/player/play',
headers: {
'Authorization': 'Bearer ' + access_token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
json: { "context_uri": uri }
};
request.put(options, function(error, response, body) {
etc
}
In other words, use json, rather than data.
Upvotes: 1