"Save Tracks for User" example not working with cURL

Reply
Highlighted

"Save Tracks for User" example not working with cURL

Regular

I just tried to use the example in https://developer.spotify.com/documentation/web-api/reference/library/save-tracks-user/ and this was not working as expected.

 

I just did a copy/paste (and replaced my Authorization header of course) and I got an error 400 "Malformed json payload".

2 Replies
Highlighted

Re: "Save Tracks for User" example not working with cURL

Rock Star 16
Rock Star 16

Hey @Nohanna, thanks for coming to the Community for help!

 

I'd love to take a closer look at this. Could you tell me a bit more about the request you're making with cURL, if possible, could you send over the full request details? That way, I'll be able to replicate this and dive into what might be going on here. Keep me in loop!

Have a good one,

Hubo

HuboRock Star 16
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.
Highlighted

Re: "Save Tracks for User" example not working with cURL

Regular

Hi Hubo!

Sure, there it is:

curl -i -X PUT "https://api.spotify.com/v1/me/tracks" -H "Authorization: Bearer my_token" -H "Content-Type: application/json" --data "{ids:[\"5ZVujHtwnsqFJvLnqRSdch\"]}"
HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
cache-control: private, max-age=0
x-robots-tag: noindex, nofollow
access-control-allow-origin: *
access-control-allow-headers: Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context
access-control-allow-methods: GET, POST, OPTIONS, PUT, DELETE, PATCH
access-control-allow-credentials: true
access-control-max-age: 604800
Content-Length: 82
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
date: Tue, 22 Sep 2020 18:48:06 GMT
server: envoy
Via: HTTP/2 edgeproxy, 1.1 google
Alt-Svc: clear

{
    "error" : {
        "status" : 400,
        "message" : "Malformed json payload"
    }
}

I tried with another track ID but it is also not working with the example in the docs! 🙂
I was wondering if it was due to an update of the endpoints because I checked the new version of the docs (cf. https://developer.spotify.com/documentation/web-api/reference-beta/#endpoint-save-tracks-user) and I couldn't find Body Parameters here, only Query Parameters.

But I tried with my app with a body and it is working, so I'm not sure what is going on.

SUGGESTED POSTS