Utilizing the spotify-web-api-js has been a smooth experience for me when interacting with Spotify Web API.
However, whenever I attempt to use the transferMyPlayback() method to switch devices, I consistently run into an error response indicating a malformed JSON.
response: "{\n \"error\" : {\n \"status\" : 400,\n \"message\" : \"Malformed json\"\n }\n}"
This method requires a JSON array that includes the device ID.
Below is a snippet of my code:
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)
});
When I log deviceIds_JSON to the console, it looks like this:
{"device_ids":["948b56d03d394e0533f198152b852eef85799df2"]}
I have attempted various methods to manipulate the JSON but continue to face a 400 error - malformed JSON message.
In addition, I tried inputting the deviceIds_JSON output in the Request Body on the Spotify Web-API Console, which generates a curl command that functions perfectly when executed from the console. This has left me feeling a bit puzzled.
If anyone could offer insight into where the issue may lie, I would greatly appreciate it.
Thank you in advance <3