Home > Net >  How to add uris to post request in javascript
How to add uris to post request in javascript

Time:03-08

I can't seem to figure out how to add uris to a post request like in this api request: https://developer.spotify.com/console/post-playlist-tracks/?playlist_id=3cEYpjA9oz9GiPac4AsH4n&position=&uris=spotify:track:4iV5W9uYEdYUVa79Axb7Rh,spotify:track:1301WleyT98MSxVHPZCA6M

this is what my request looks like currently put does not work

fetch(endPoint, {
method: "POST",
headers: {
  Authorization: `Bearer ${access_token}`,
},
body: JSON.stringify({
  "uri": data
})
});

thanks in advance for any help

CodePudding user response:

Based on this doc: https://developer.spotify.com/documentation/web-api/reference/#/operations/add-tracks-to-playlist

It looks like you have the format of the body wrong. It should look something like this:

    fetch(endPoint, {
        method: "POST",
        headers: {
            Authorization: `Bearer ${access_token}`,
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            uris: [
                "uri-1",
                "uri-2",
            ],
        })
    });
  • Related