Reputation: 37
I've been using spotify-web-api-js to interact with Spotify Web API, so far without any trouble.
However, when I try to use the transferMyPlayback() method to change the device, I always receive an error response pointing to a malformed JSON.
response: "{\n \"error\" : {\n \"status\" : 400,\n \"message\" : \"Malformed json\"\n }\n}"
This method takes a JSON array containing the device ID.
Here's my code for this :
var deviceIds = {}
deviceIds["device_ids"] = [id]
var deviceIds_JSON = JSON.stringify(deviceIds)
spotifyApi.transferMyPlayback(deviceIds_JSON)
.then(function(data){
console.log(data)
}, function(err){
console.log(err)
});
Console.log(deviceIds_JSON) gives something like this :
{"device_ids":["948b56d03d394e0533f198152b852eef85799df2"]}
I've tried several things to manipulate the JSON, but always end up with an error 400 - malformed JSON message.
I also tried to feed the Spotify Web-API Console Request Body with the deviceIds_JSON output above, which gives me a curl command ... that works perfectly when executed from console. So, yeah ... I'm a bit confused, there.
Can anyone point me in the right direction as to where the problem might be ?
Thanks in advance <3
Upvotes: 0
Views: 493