Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

502 Bad Gateway from top items endpoints #26

Closed
ReubenFrankel opened this issue Feb 21, 2024 · 1 comment · Fixed by #27
Closed

502 Bad Gateway from top items endpoints #26

ReubenFrankel opened this issue Feb 21, 2024 · 1 comment · Fixed by #27
Labels
bug Something isn't working upstream Related to an upstream dependency or service

Comments

@ReubenFrankel
Copy link
Contributor

ReubenFrankel commented Feb 21, 2024

Looks like something changed on Spotify's side that started causing 502 Bad Gateway errors when accessing top tracks/artists, where the combined value of limit and offset parameters exceeds the total number of items - 100:

{
    "error": {
        "status": 502,
        "message": ""
    }
}

Working

https://api.spotify.com/v1/me/top/tracks?offset=99&limit=1
https://api.spotify.com/v1/me/top/tracks?offset=50&limit=50
https://api.spotify.com/v1/me/top/tracks?offset=49&limit=49

Broken

https://api.spotify.com/v1/me/top/tracks?offset=100&limit=1
https://api.spotify.com/v1/me/top/tracks?offset=51&limit=50
https://api.spotify.com/v1/me/top/tracks?offset=98&limit=49

We originally defined a limit of 49 for top items streams in order to maximise the amount of data returned (i.e. over 100 items) by exploiting a previous quirk of the API, where paginating with next links yielded an "extra" 49 items (147 total):

1st request

{
    "items": [...
    ],
    "total": 100,
    "limit": 49,
    "offset": 0,
    "href": "https://api.spotify.com/v1/me/top/tracks?limit=49",
    "next": "https://api.spotify.com/v1/me/top/tracks?offset=49&limit=49",
    "previous": null
}

2nd request

{
    "items": [...
    ],
    "total": 100,
    "limit": 49,
    "offset": 49,
    "href": "https://api.spotify.com/v1/me/top/tracks?offset=49&limit=49",
    "next": "https://api.spotify.com/v1/me/top/tracks?offset=98&limit=49",
    "previous": "https://api.spotify.com/v1/me/top/tracks?offset=0&limit=49"
}

3rd request (now 502 Bad Gateway) - no next link, pagination stops

{
    "items": [...
    ],
    "total": 100,
    "limit": 49,
    "offset": 98,
    "href": "https://api.spotify.com/v1/me/top/tracks?offset=98&limit=49",
    "next": null,
    "previous": "https://api.spotify.com/v1/me/top/tracks?offset=49&limit=49"
}

If 50 was used instead, pagination would stop at ?limit=50&offset=50 (100 total):

1st request

{
    "items": [...
    ],
    "total": 100,
    "limit": 50,
    "offset": 0,
    "href": "https://api.spotify.com/v1/me/top/tracks?limit=50",
    "next": "https://api.spotify.com/v1/me/top/tracks?offset=50&limit=50",
    "previous": null
}

2nd request - no next link, pagination stops

{
    "items": [...
    ],
    "total": 100,
    "limit": 50,
    "offset": 50,
    "href": "https://api.spotify.com/v1/me/top/tracks?offset=50&limit=50",
    "next": null,
    "previous": "https://api.spotify.com/v1/me/top/tracks?offset=0&limit=50"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream Related to an upstream dependency or service
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant