spotify / web-api

This issue tracker is no longer used. Join us in the Spotify for Developers forum for support with the Spotify Web API ➡️ https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer
983 stars 79 forks source link

Docs for remove tracks from playlist with snapshot is wrong #1482

Closed vorce closed 4 years ago

vorce commented 4 years ago

Issue found on February 22th 2020.

Endpoint(s):

Scope(s):

Steps to reproduce:

  1. Open https://developer.spotify.com/documentation/web-api/reference/playlists/remove-tracks-playlist/
  2. Go to the "Removing a specific occurrence of a track in a specific playlist snapshot" section
  3. The docs say that you should specify the snapshot_id field.
  4. Make a valid request like the docs describe, something like
curl -XDELETE https://api.spotify.com/v1/playlists/xyz/tracks -H 'Authorization: Bearer access_token' -H 'Content-type: application/json' -d '{"tracks": [{"uri":"spotify:track:xyz"}], "snapshot_id": "xyz"}'

Expected behaviour:

Track is deleted from playlist.

Actual behaviour:

Track remains in playlist (consistently). If you specify snapshot instead of snapshot_id it works as intended.

felix-hilden commented 4 years ago

That would be quite bad if that were the case. But I can't reproduce the problem, at least in code. Maybe it's an issue with the console or setup in your case?

Here's some Python to test the issue.

from tekore import Spotify, util, scope

conf = ('client_id', 'client_secret', 'redirect_uri')
token = util.prompt_for_user_token(*conf, scope=scope.every)

spotify = Spotify(token)

# Get tracks of a featured playlist
_, featured = spotify.featured_playlists(limit=1)
mirror = featured.items[0]
tracks = spotify.playlist_tracks(mirror.id)
track_ids = [t.track.id for t in tracks.items]

# Create playlist
user = spotify.current_user()
playlist = spotify.playlist_create(user.id, 'Snapshot test', public=False)
snapshot = spotify.playlist_tracks_add(playlist.id, track_ids)
tracks_1 = spotify.playlist_tracks(playlist.id)
track_ids_1 = [t.track.id for t in tracks_1.items]

# Remove one track
spotify.playlist_tracks_remove(playlist.id, track_ids[:1], snapshot_id=snapshot)
tracks_2 = spotify.playlist_tracks(playlist.id)
track_ids_2 = [t.track.id for t in tracks_2.items]

print('Track in playlist before removal:', track_ids[0] in track_ids_1)
print('Track in playlist after removal:', track_ids[0] in track_ids_2)

# Clean up
spotify.playlist_unfollow(playlist.id)
vorce commented 4 years ago

Yes looks like I'm mistaken. Could've sworn something was weird when I tried it at the time of submission. Works perfectly fine when I try it now :) Thanks and sorry 🤷‍♂

Here's the bash script (requires jq though) I used to verify:

#!/bin/bash
# Delete the first track of a playlist.
# Expects two arguments, a valid bearer token and a playlist id.

token=$1
playlist_id=$2

playlist_info=$(curl -s -X GET "https://api.spotify.com/v1/playlists/$playlist_id" -H "Authorization: Bearer $token")

snapshot_id=$(echo $playlist_info | jq -r ".snapshot_id")
first_track=$(echo $playlist_info | jq ".tracks.items[0]")
first_track_uri=$(echo $first_track | jq -r ".track.uri")

delete_track_payload=$(jq -n \
                  --arg uri1 $first_track_uri \
                  --arg snap_id $snapshot_id \
                  '{tracks: [{uri: $uri1}], snapshot_id: $snap_id}')

echo "delete payload: $delete_track_payload"

curl -X DELETE -i -H "Authorization: Bearer $token" -H "Content-Type: application/json" "https://api.spotify.com/v1/playlists/$playlist_id/tracks" --data "$delete_track_payload"

echo "Playlist after deletion:"
curl -s -X GET "https://api.spotify.com/v1/playlists/$playlist_id" -H "Authorization: Bearer $token"