<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Incorrect pagination https://api.spotify.com/v1/users/{user_id}/playlists in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Incorrect-pagination-https-api-spotify-com-v1-users-user-id/m-p/6058013#M13854</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Canada&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;REST API&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Hi everyone!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I ran into a weird issue with paginating over users playlists. Steps to reproduce are:&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Request some number of users playlists with no offset: &lt;STRONG&gt;?limit=5&amp;amp;offset=0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Request same amount of playlists for the "next page", i.e. offset of the second request is equal limit of the first one:&amp;nbsp;&lt;STRONG&gt;?limit=5&amp;amp;offset=5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;Expected result&lt;/STRONG&gt;: in total, 10 unique playlists are returned.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;Actual result&lt;/STRONG&gt;:in total, 9&amp;nbsp;unique playlists are returned.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Since third page it works as expected, i.e. two requests with &lt;STRONG&gt;?limit=5&amp;amp;offset=5&lt;/STRONG&gt; and &lt;STRONG&gt;?limit=5&amp;amp;offset=10&lt;/STRONG&gt; return&amp;nbsp;non-intersecting lists of items.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Below is a python snippet for reproducing.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;It prints:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;['6kL8wAlMOYicjD4WE5h5UY', '0L5Ub41BC6UPiOR2i99XDE', '37i9dQZEVXcGu90ywFf8Id', '37i9dQZEVXbmu9hXKCIN5q', '4uJLFAfVHXIGUWIRj95BZ5']
['4uJLFAfVHXIGUWIRj95BZ5', '6NQkzRDINJC25OefUAz8g3', '4jLfWUF6JBVwaieOu8er6K', '1VER2y1u7Q3ymjNscEQoXc', '0VC4kqlB1SdoJsihGG2Vya']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The last item of the first list is equal to the first item of the second list:&lt;/FONT&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;4uJLFAfVHXIGUWIRj95BZ5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Since next page it start working nornally:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#000000"&gt;prints&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;['1lm98dZ23rv7bFlOkTj5yV', '37EgzYlwQVFPKUUrKTcDvq', '7fSyMpbKv4gH4pJV04JjcJ', '6sGesrjKWbNTVN3YNMJlXl', '2QzAr27YvIQOyB72lySjzW']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;which is correct since it doesn't share items with previous pages.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;What is also strange is that this "overlapping" depends on limit. For instance, for limit=3:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;['6kL8wAlMOYicjD4WE5h5UY', '0L5Ub41BC6UPiOR2i99XDE', '37i9dQZEVXcGu90ywFf8Id']
['37i9dQZEVXbmu9hXKCIN5q', '4uJLFAfVHXIGUWIRj95BZ5', '6NQkzRDINJC25OefUAz8g3']
['6NQkzRDINJC25OefUAz8g3', '4jLfWUF6JBVwaieOu8er6K', '1VER2y1u7Q3ymjNscEQoXc']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;overlapping happens for 2nd and 3rd pages:&amp;nbsp;&lt;STRONG&gt;6NQkzRDINJC25OefUAz8g3.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Same for limit=4. But since limit=5 overlapping happens between 1st and 2nd pages.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Let me know what you think about it, and please do let me know if any extra information is required!&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2024 01:16:42 GMT</pubDate>
    <dc:creator>perminovsi</dc:creator>
    <dc:date>2024-05-09T01:16:42Z</dc:date>
    <item>
      <title>Incorrect pagination https://api.spotify.com/v1/users/{user_id}/playlists</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Incorrect-pagination-https-api-spotify-com-v1-users-user-id/m-p/6058013#M13854</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Canada&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;REST API&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Hi everyone!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I ran into a weird issue with paginating over users playlists. Steps to reproduce are:&lt;/FONT&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Request some number of users playlists with no offset: &lt;STRONG&gt;?limit=5&amp;amp;offset=0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT color="#000000"&gt;Request same amount of playlists for the "next page", i.e. offset of the second request is equal limit of the first one:&amp;nbsp;&lt;STRONG&gt;?limit=5&amp;amp;offset=5&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;Expected result&lt;/STRONG&gt;: in total, 10 unique playlists are returned.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;Actual result&lt;/STRONG&gt;:in total, 9&amp;nbsp;unique playlists are returned.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Since third page it works as expected, i.e. two requests with &lt;STRONG&gt;?limit=5&amp;amp;offset=5&lt;/STRONG&gt; and &lt;STRONG&gt;?limit=5&amp;amp;offset=10&lt;/STRONG&gt; return&amp;nbsp;non-intersecting lists of items.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Below is a python snippet for reproducing.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;It prints:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;['6kL8wAlMOYicjD4WE5h5UY', '0L5Ub41BC6UPiOR2i99XDE', '37i9dQZEVXcGu90ywFf8Id', '37i9dQZEVXbmu9hXKCIN5q', '4uJLFAfVHXIGUWIRj95BZ5']
['4uJLFAfVHXIGUWIRj95BZ5', '6NQkzRDINJC25OefUAz8g3', '4jLfWUF6JBVwaieOu8er6K', '1VER2y1u7Q3ymjNscEQoXc', '0VC4kqlB1SdoJsihGG2Vya']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The last item of the first list is equal to the first item of the second list:&lt;/FONT&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;4uJLFAfVHXIGUWIRj95BZ5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Since next page it start working nornally:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#000000"&gt;prints&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;['1lm98dZ23rv7bFlOkTj5yV', '37EgzYlwQVFPKUUrKTcDvq', '7fSyMpbKv4gH4pJV04JjcJ', '6sGesrjKWbNTVN3YNMJlXl', '2QzAr27YvIQOyB72lySjzW']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;which is correct since it doesn't share items with previous pages.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;What is also strange is that this "overlapping" depends on limit. For instance, for limit=3:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;['6kL8wAlMOYicjD4WE5h5UY', '0L5Ub41BC6UPiOR2i99XDE', '37i9dQZEVXcGu90ywFf8Id']
['37i9dQZEVXbmu9hXKCIN5q', '4uJLFAfVHXIGUWIRj95BZ5', '6NQkzRDINJC25OefUAz8g3']
['6NQkzRDINJC25OefUAz8g3', '4jLfWUF6JBVwaieOu8er6K', '1VER2y1u7Q3ymjNscEQoXc']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;overlapping happens for 2nd and 3rd pages:&amp;nbsp;&lt;STRONG&gt;6NQkzRDINJC25OefUAz8g3.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Same for limit=4. But since limit=5 overlapping happens between 1st and 2nd pages.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Let me know what you think about it, and please do let me know if any extra information is required!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 01:16:42 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Incorrect-pagination-https-api-spotify-com-v1-users-user-id/m-p/6058013#M13854</guid>
      <dc:creator>perminovsi</dc:creator>
      <dc:date>2024-05-09T01:16:42Z</dc:date>
    </item>
  </channel>
</rss>

