Closed vorce closed 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)
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"
Issue found on February 22th 2020.
Endpoint(s):
DELETE v1/playlists/{playlist_id}/tracks
Scope(s):
Steps to reproduce:
snapshot_id
field.Expected behaviour:
Track is deleted from playlist.
Actual behaviour:
Track remains in playlist (consistently). If you specify
snapshot
instead ofsnapshot_id
it works as intended.