[GH-ISSUE #215] Paging when number of tracks returned by getPlaylist > 100 #150

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

Originally created by @ghost on GitHub (Jan 3, 2021).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/215

Hi Jonathan,

When using the getPlaylist method, e.g. for playlist ID 6BcaB4qmXheLL2VWDO65h5, the default limit is that 100 tracks are returned in the API response from Spotify, unless a limit value is specified in the options. I'm calling the API like this, with limit set to 10, and offset also set to 10:

try {
    $playlist_options = ['offset' => 10, 'limit' => 10];
    $playlist = $api->getPlaylist('6BcaB4qmXheLL2VWDO65h5', $playlist_options);
} catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
	header('Location:index.php');
	exit;
}

Playlist ID 6BcaB4qmXheLL2VWDO65h5 contains 102 tracks, but the response from Spotify via the above call looks like this:

href=>https://api.spotify.com/v1/playlists/6BcaB4qmXheLL2VWDO65h5/tracks?offset=0&limit=10
items=>array(100)
limit=>10
next=>https://api.spotify.com/v1/playlists/6BcaB4qmXheLL2VWDO65h5/tracks?offset=10&limit=10
offset=>0
previous=>null
total=>102

Here you can see:

  1. 100 tracks are returned rather than 10 even though the href and next values show the limit is set to 10
  2. The offset value from the options is ignored

The Spotify Docs say for Limit and Offset:

  • Limit: The maximum number of items in the response (as set in the query or by default).
  • Offset: The offset of the items returned (as set in the query or by default).

I wondered if I'm missing something obvious, or if it's not possible to paginate through the tracks?

Thanks

Jim

Originally created by @ghost on GitHub (Jan 3, 2021). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/215 Hi Jonathan, When using the `getPlaylist` method, e.g. for playlist ID 6BcaB4qmXheLL2VWDO65h5, the default limit is that 100 tracks are returned in the API response from Spotify, unless a `limit` value is specified in the options. I'm calling the API like this, with `limit` set to 10, and `offset` also set to 10: ``` try { $playlist_options = ['offset' => 10, 'limit' => 10]; $playlist = $api->getPlaylist('6BcaB4qmXheLL2VWDO65h5', $playlist_options); } catch (SpotifyWebAPI\SpotifyWebAPIException $e) { header('Location:index.php'); exit; } ``` Playlist ID 6BcaB4qmXheLL2VWDO65h5 contains 102 tracks, but the response from Spotify via the above call looks like this: ``` href=>https://api.spotify.com/v1/playlists/6BcaB4qmXheLL2VWDO65h5/tracks?offset=0&limit=10 items=>array(100) limit=>10 next=>https://api.spotify.com/v1/playlists/6BcaB4qmXheLL2VWDO65h5/tracks?offset=10&limit=10 offset=>0 previous=>null total=>102 ``` Here you can see: 1. 100 tracks are returned rather than 10 even though the `href` and `next` values show the limit is set to 10 2. The offset value from the options is ignored The [Spotify Docs](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/#paging-object) say for Limit and Offset: - Limit: The maximum number of items in the response (as set in the query or by default). - Offset: The offset of the items returned (as set in the query or by default). I wondered if I'm missing something obvious, or if it's not possible to paginate through the tracks? Thanks Jim
kerem 2026-02-27 19:26:19 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Jan 3, 2021):

Hi Jim!
Happy new year!

I think the method you're looking for is getPlaylistTracks() which should be more efficient as well if you're only after the tracks. It accepts the same parameters as getPlaylist().

I do agree it's strange that limit and offset is included in the href property.

Cheers,
Jonathan

<!-- gh-comment-id:753658445 --> @jwilsson commented on GitHub (Jan 3, 2021): Hi Jim! Happy new year! I think the method you're looking for is `getPlaylistTracks()` which should be more efficient as well if you're only after the tracks. It accepts the same parameters as `getPlaylist()`. I do agree it's strange that `limit` and `offset` is included in the `href` property. Cheers, Jonathan
Author
Owner

@ghost commented on GitHub (Jan 20, 2021):

Hi Jonathan - Happy Three Week Old Year to you :-)

Thanks for your helpful reply - I forgot to close this issue - your suggestion worked, to use 'getPlaylistTracks()'.

Excellent - thank you!

Jim

<!-- gh-comment-id:763405804 --> @ghost commented on GitHub (Jan 20, 2021): Hi Jonathan - Happy Three Week Old Year to you :-) Thanks for your helpful reply - I forgot to close this issue - your suggestion worked, to use 'getPlaylistTracks()'. Excellent - thank you! Jim
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#150
No description provided.