mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-27 07:55:49 +03:00
[GH-ISSUE #132] I can't delete the playlist tracks by position #79
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#79
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raulojeda22 on GitHub (Jul 4, 2018).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/132
I want to delete all the tracks of a playlist and I have a code more or less like this:
But it outputs the error: JSON body doesn't conform to specification
But it outputs the error: Missing or invalid positions
Expected behaviour:
I want to remove the first track of the playlist until $snapshotId becomes false (the playlist is empty)
@jwilsson commented on GitHub (Jul 4, 2018):
Hi!
positionsneeds to be an array too, so this should work:I think though, in this case
replacePlaylistTracksmight be a better fit. That is, if you only want to clear a playlist. That will be quicker and a$snapshotIdwill always be returned fromdeletePlaylistTracks, even when the playlist is empty.An example using
replacePlaylistTracks:Passing an empty list of tracks will clear the whole playlist in one go.
Hope this helps!
@raulojeda22 commented on GitHub (Jul 5, 2018):
Hi Jwilsson! Thanks for the quick reply. In this case replacePlaylistTracks made the job for me, unfortunately using positions as an array also failed with the message:
"Could not remove tracks, please check parameters."
I'm not sure why this happens, so I will leave it to you. When you find the solution you could update the managing-user-playlists.md file in the "Delete tracks from a user's playlist based on positions" section since it doesn't fit the correct answer. I think that more or less would end up like this:
It would change from this:
$trackPositions = [
5,
12,
];
$api->deletePlaylistTracks('USER_ID', 'PLAYLIST_ID', $trackPositions, 'SNAPSHOT_ID');
To more or less this:
$trackPositions = [
'positions' => [5,12]
];
$api->deletePlaylistTracks('PLAYLIST_ID', $trackPositions, 'SNAPSHOT_ID');
I was a bit confused at the beginning because this example didn't matched the definition of the method in SpotifyWebAPI.md: "Or an array with the key "positions" containing integer positions of the tracks to delete."
Just wanted to say, thanks a bunch for your time and your help!
@jwilsson commented on GitHub (Jul 5, 2018):
No worries @raulojeda22, glad I could help!
I'll take another look at the docs.