Top Games returning N-1 results


#1

When hitting the new API for top games getting an incorrect number of games returned. Seems to be n-1 requested after first is equal to 3 all the way up to 100.

$ curl -H “Authorization: Bearer ${TOKEN}” -s https://api.twitch.tv/helix/games/top?first=3 | jshon

{
“data”: [
{
“id”: “509658”,
“name”: “Just Chatting”,
“box_art_url”: “https://static-cdn.jtvnw.net/ttv-boxart/Just%20Chatting-{width}x{height}.jpg
},
{
“id”: “491931”,
“name”: “Escape From Tarkov”,
“box_art_url”: “https://static-cdn.jtvnw.net/ttv-boxart/Escape%20From%20Tarkov-{width}x{height}.jpg
}
],
“pagination”: {
“cursor”: “eyJzIjozLCJkIjpmYWxzZSwidCI6dHJ1ZX0=”
}
}


#2

I can’t replicate it here!

I get three

You still not getting the amount you are asking for?


#3

Three working ok but now the number seems to be 11 returning 10

Taking off the first so the default of 20 is used is similarly returning 19.

Seems to be easier to replicate when using a high number like first=100


#4

Hmm I wonder if the “missing game” is for “game is not set”


#5

That’s correct. "game_id": "" is filtered out of the results of top games, but is done so after the results are returned from the database/cache, so if that game id is in the results range requested, it’ll get dropped and you’ll end up with first - 1 results.

This can be verified by using https://api.twitch.tv/helix/streams?game_id=0, paging through the results and summing the viewer count. The position where that game would be, if it was included, is consistent with where you start seeing a results returning fewer than the first param.


#6

Oh good catch, that explains why the result was moving as well at different times

Thanks for the tip, I’ll code around that idea or just always request n+1 since I can just drop the extra on my side if it isn’t needed at the time.