[GH-ISSUE #115] Add track to playlist prepend (position 0) instead of append to end #69

Closed
opened 2026-02-27 19:25:53 +03:00 by kerem · 2 comments
Owner

Originally created by @kasperkamperman on GitHub (Feb 25, 2018).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/115

The Spotify API supports the optional position integer. I'd like to use it to add a new track as the first track of the playlist.

I'm not an PHP expert, so I'm wondering how I can reach this. I tried:

  • $api->addUserPlaylistTracks($me->id, $playlistId, '6sLY2CNublHBA0nsjnXvGR', ['position=0']);
  • $api->addUserPlaylistTracks($me->id, $playlistId, '6sLY2CNublHBA0nsjnXvGR', ['\"position\": 0']);
  • $api->addUserPlaylistTracks($me->id, $playlistId, ['59FjL5y7X8P8PmR8o9lmpi'],['\"position\": 0']);

But none of it works. It seems that I can use the option array in your php code but probably I don't form the data well? There is no error thrown, the track just keeps being appended to the end of the list.

I hope you can help. Thank you in advance for your time.

Originally created by @kasperkamperman on GitHub (Feb 25, 2018). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/115 The [Spotify API](https://developer.spotify.com/web-api/add-tracks-to-playlist/) supports the optional position integer. I'd like to use it to add a new track as the first track of the playlist. I'm not an PHP expert, so I'm wondering how I can reach this. I tried: - ```$api->addUserPlaylistTracks($me->id, $playlistId, '6sLY2CNublHBA0nsjnXvGR', ['position=0']);``` - ```$api->addUserPlaylistTracks($me->id, $playlistId, '6sLY2CNublHBA0nsjnXvGR', ['\"position\": 0']);``` - ```$api->addUserPlaylistTracks($me->id, $playlistId, ['59FjL5y7X8P8PmR8o9lmpi'],['\"position\": 0']);``` But none of it works. It seems that I can use the option array in your [php code](https://github.com/jwilsson/spotify-web-api-php/blob/master/src/SpotifyWebAPI.php#L154) but probably I don't form the data well? There is no error thrown, the track just keeps being appended to the end of the list. I hope you can help. Thank you in advance for your time.
kerem 2026-02-27 19:25:53 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@andersborgabiro commented on GitHub (Feb 26, 2018):

The syntax should be:

$api->addUserPlaylistTracks($me->id, $playlistId, ['someTrackId'], ['position' => 0]);

Whether it has the intended effect of prepending the track I don't know.

<!-- gh-comment-id:368360116 --> @andersborgabiro commented on GitHub (Feb 26, 2018): The syntax should be: $api->addUserPlaylistTracks($me->id, $playlistId, ['someTrackId'], ['position' => 0]); Whether it has the intended effect of prepending the track I don't know.
Author
Owner

@jwilsson commented on GitHub (Feb 26, 2018):

Hi @kasperkamperman!
@andersborgabiro is absolutely correct, the syntax should be:

$api->addUserPlaylistTracks($me->id, $playlistId, 'someTrackId', ['position' => 0]);

// Or to add multiple tracks
$api->addUserPlaylistTracks($me->id, $playlistId, ['someTrackId', 'someOtherTrackId'], ['position' => 0]);

And this will prepend the track(s) as expected.

<!-- gh-comment-id:368392973 --> @jwilsson commented on GitHub (Feb 26, 2018): Hi @kasperkamperman! @andersborgabiro is absolutely correct, the syntax should be: ```php $api->addUserPlaylistTracks($me->id, $playlistId, 'someTrackId', ['position' => 0]); // Or to add multiple tracks $api->addUserPlaylistTracks($me->id, $playlistId, ['someTrackId', 'someOtherTrackId'], ['position' => 0]); ``` And this will prepend the track(s) as expected.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#69
No description provided.