Announcements

Help Wizard

Step 1

NEXT STEP

How delete one or more elements from playlist?

Solved!

How delete one or more elements from playlist?

If you use the API https://api.spotify.com/v1/playlists/{playlist_id}/tracks it removes ALL TRACKS from the playlist that match the given URI.

But how can I delete one track? Or a certain number of tracks with such a URI?

Reply

Accepted Solutions
Marked as solution

There's another format for the body of the request that is missing from the documentation. You can specify the position of the items in the playlist:

{
    "tracks": [
        {
            "uri": "spotify:track:4HDLmWf73mge8isanCASnU",
            "positions": [1, 4]
        },
        {
            "uri": "spotify:track:0bxcUgWlOURkU6lZt4zog0",
            "positions":[2, 3]
        }
    ]
}

Use the same endpoint mentioned in the previous comments.

View solution in original post

10 Replies

Anyone can help?


There is also a problem with getting the correct URIs for songs via https://api.spotify.com/v1/me/tracks.
If you receive URIs for songs through https://api.spotify.com/v1/me/tracks, then these URIs are different from the URIs in the library.

Up, help guys

Hey there, help's here!

 

Let's dive right into this. You can find more information about removing tracks from a playlist here: https://developer.spotify.com/documentation/web-api/reference/#endpoint-remove-tracks-playlist.

You can use that endpoint to remove tracks. Here's an example request:

curl -X "DELETE" "https://api.spotify.com/v1/playlists/PLAYLISTID/tracks" --data "{\"tracks\":[{\"uri\":\"TRACKID\"}]}" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer XXXXX"

 That should help here. Let me know how you get on!

 

Have a great day,

Hubo

HuboSpotify Star
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.

Thanks for the answer.

 

My request is 

 

{"tracks": [{"uri": "spotify:track:1L3AZIJzMvE08VvBkeFJvg"}]}

 

And API deletes all tracks in playlist, which matches URI spotify:track:1L3AZIJzMvE08VvBkeFJvg

 

For example, i have 5 songs with URI spotify:track:1L3AZIJzMvE08VvBkeFJvg in playlist, and this request deletes all songs that matches this URI. But i want to delete 1 song, not all.

 

This is my video with my actions.

https://youtu.be/ZbAOVjb1r4I

Help
Marked as solution

There's another format for the body of the request that is missing from the documentation. You can specify the position of the items in the playlist:

{
    "tracks": [
        {
            "uri": "spotify:track:4HDLmWf73mge8isanCASnU",
            "positions": [1, 4]
        },
        {
            "uri": "spotify:track:0bxcUgWlOURkU6lZt4zog0",
            "positions":[2, 3]
        }
    ]
}

Use the same endpoint mentioned in the previous comments.

Marked as solution

Yeah, thanks, it works.

I tested with position parameter previously, but it didn't work.
Only then I realized that the tracks are added to the end of the playlist, not the beginning 🙂 

is this still supported? can't get positions to work

Hello,

For me works. 
Just make sure that first it works without the positions.

Then pass in an integer, if you are using variable make sure it is also an integer.

   "tracks": [
            {
            "uri": `spotify:track:${songId}`,
            "positions": [songToRemoveIndex]
          }
          ]

songToRemoveIndex -> parseInt(event.target.getAttribute('index'), 10)

 
 




 

 

Suggested posts