Incorrect pagination https://api.spotify.com/v1/users/{user_id}/playlists

Plan

Premium

Country

Canada

Device

REST API

My Question or Issue

 

Hi everyone!

I ran into a weird issue with paginating over users playlists. Steps to reproduce are:

  1. Request some number of users playlists with no offset: ?limit=5&offset=0
  2. Request same amount of playlists for the "next page", i.e. offset of the second request is equal limit of the first one: ?limit=5&offset=5

Expected result: in total, 10 unique playlists are returned.

Actual result:in total, 9 unique playlists are returned.

Since third page it works as expected, i.e. two requests with ?limit=5&offset=5 and ?limit=5&offset=10 return non-intersecting lists of items.

 

Below is a python snippet for reproducing.

 

import requests
token = '...'

user_id = 'ht1j0ynnwu4hdgfw6g7a0y1nx'

response1 = requests.request(
    method='GET',
    url=f'https://api.spotify.com/v1/users/{user_id}/playlists',
    params={'limit': 5, 'offset': 0},
    headers={'Authorization': f'Bearer {token}'},
)
items1 = [(p['id']) for p in response1.json()['items']]

response2 = requests.request(
    method='GET',
    url=f'https://api.spotify.com/v1/users/{user_id}/playlists',
    params={'limit': 5, 'offset': 5},
    headers={'Authorization': f'Bearer {token}'},
)
items2 = [(p['id']) for p in response2.json()['items']]

print(items1)
print(items2)

 

It prints:

 

['6kL8wAlMOYicjD4WE5h5UY', '0L5Ub41BC6UPiOR2i99XDE', '37i9dQZEVXcGu90ywFf8Id', '37i9dQZEVXbmu9hXKCIN5q', '4uJLFAfVHXIGUWIRj95BZ5']
['4uJLFAfVHXIGUWIRj95BZ5', '6NQkzRDINJC25OefUAz8g3', '4jLfWUF6JBVwaieOu8er6K', '1VER2y1u7Q3ymjNscEQoXc', '0VC4kqlB1SdoJsihGG2Vya']

 

 

The last item of the first list is equal to the first item of the second list: 4uJLFAfVHXIGUWIRj95BZ5.

Since next page it start working nornally:

 

response3 = requests.request(
    method='GET',
    url=f'https://api.spotify.com/v1/users/{user_id}/playlists',
    params={'limit': 5, 'offset': 10},
    headers={'Authorization': f'Bearer {token}'},
)
items3 = [(p['id']) for p in response3.json()['items']]

print(items3)

 

 prints

 

['1lm98dZ23rv7bFlOkTj5yV', '37EgzYlwQVFPKUUrKTcDvq', '7fSyMpbKv4gH4pJV04JjcJ', '6sGesrjKWbNTVN3YNMJlXl', '2QzAr27YvIQOyB72lySjzW']

 

 which is correct since it doesn't share items with previous pages.

What is also strange is that this "overlapping" depends on limit. For instance, for limit=3:

 

['6kL8wAlMOYicjD4WE5h5UY', '0L5Ub41BC6UPiOR2i99XDE', '37i9dQZEVXcGu90ywFf8Id']
['37i9dQZEVXbmu9hXKCIN5q', '4uJLFAfVHXIGUWIRj95BZ5', '6NQkzRDINJC25OefUAz8g3']
['6NQkzRDINJC25OefUAz8g3', '4jLfWUF6JBVwaieOu8er6K', '1VER2y1u7Q3ymjNscEQoXc']

 

overlapping happens for 2nd and 3rd pages: 6NQkzRDINJC25OefUAz8g3.

Same for limit=4. But since limit=5 overlapping happens between 1st and 2nd pages.

 

Let me know what you think about it, and please do let me know if any extra information is required!

Child Item
Child Item
Child Item

Accepted answers

All comments

Child Item
Child Item