Announcements

Help Wizard

Step 1

NEXT STEP

Get Current User's Playlists returns incorrect data when DJ is present

Get Current User's Playlists returns incorrect data when DJ is present

I'm building an app that gets the current users playlist, I noticed that 'total' seems to differ from the actual amount of playlists returned. Investigating further I noticed that the API returns duplicate playlist entries when the playlist is next to 'DJ' and the limit/offset range includes DJ, when limit/offset is out of the range of DJ, everything works as intended.

I assume this is because 'DJ' is counted towards the total number of playlists, but is excluded from the results. This adds unwanted complexity to my app by having to be aware of phantom playlists, duplicate entries, and to not trust the 'total' returned from the API.
Reply
2 Replies

I'm seeing something similar, though I'm not noticing any correlation with DJ.
I'm seeing duplicate playlists returned as well, and they seem to be counting toward the `total` in the response. The ones I'm noticing are at the "edge" of a paginated list of playlists, ie. the same playlist is both the last element of a page and the first element of the next page. I don't think I have any off-by-one errors because my request matches the `next` url provided in each page. What's weird is that it seems to count toward the `total` in the response as well though.
For example, my first request `https://api.spotify.com/v1/me/playlists` will have a response with a `next` of `.../users/ID/playlists?offset=50&limit=50&locale=en-US%2Cen%3Bq%3D0.9"`, and then my next request to `.../users/ID/playlists?offset=50&limit=50&locale=en-US%2Cen%3Bq%3D0.9` will include the last playlist from the first response as the first playlist in this new request.
This doesn't happen for every request, ie. even for 10 page request for a total of 500+ playlists, I still only get 2-3 duplicates.
I could see this being a race condition, IF I were adding playlists while running the API requests (which I'm not), but it shows in the `total` response field. And that `total` matches the sum of all the array sizes after I've loaded the final page, even though the arrays include duplicates.

I saw this issue too, I had to add extra checks to see if the returned count is the same as the limit count and then i determine if i retrieved all playlists and i also just make an assumption they have less than 200 and don't try to go more than that. This dramatically reduced my calls to retrieve playlists, to be honest not sure which condition exactly i don't gather enough metrics.

Suggested posts