I’m having trouble with the Spotify Web API when trying to start playback. The API endpoint for playing music returns a 400 error saying the JSON is malformed.
When I remove the track_uris parameter, the API works fine and starts playing the last song. But with the parameter included, I get this JSON error. The data being sent looks correct to me.
spotted the issue - you’re using form_params but spotify expects raw json data. try switching to json body instead of form encoding, that should fix the malformed error you’re getting
Your content type header is wrong. You’re sending application/x-www-form-urlencoded but Spotify’s API wants application/json. Switch to the json parameter instead of form_params and fix the header. I hit this exact same issue last year with playlist controls - Spotify’s really picky about getting proper JSON instead of form data, even though it’s basically the same info.
You’re mixing content types - you declared form-encoded data but Spotify wants JSON. Switch to the json parameter instead of form_params and change your Content-Type header to application/json. Make sure your track_uris array is properly formatted as JSON too. I ran into the same issue building a playlist manager. Spotify’s endpoints are picky about getting actual JSON objects, not form-encoded arrays, even when they look the same.