API returns 500 error when making a request of a very big leaderboard
7 months ago
Belarus

I am making a program that uses API to get stats about game leaderboards, like run amont for each category, wr time, etc. To do that I do the /leaderboards/ request. From there I get "runs" which is a big array of like all runs in the leaderboard. I get the run amount by just getting the length of this array. And also from other stats I collect a special number for myself that takes the time of the (run amount * 0.9) place and divides it by (run amount * 0.1) place time, to get a number that sort of represents how much times differ in this category.

It works fine with most of the games, but sometimes when the game is very big it just... doesn't return anything. That's at least what happened with Subway Surfers. It has huge leaderboards. How can I fix my problem? Is there a way to get just the run amount without getting the gigantic array of runs and getting its length? And if there is a way, then how can I still have an access to run times in specific places of the leaderboard?

Switzerland

I ran into a similar problem a while ago. For my latest API project, a Queue client (to see pending runs), I use the plain "/runs" endpoint for a certain category, and iterate through the result pages (of 200 runs each, the maximum amount per page).

The URL would like this: "/runs?game=${gameId}&status=verified&orderby=submitted&direction=asc&max=200&offset=${offset}" with an offset of 0, 200, 400 etc. where you can loop until you reach the last page.

After that you'd have to sort that big list of runs by run time - I don't see any way in the API docs to use the "orderby" for the actual run length.

Seems a bit tedious but I can't think of another way on how to do it. (There is a "/records" shortcut on the /games-endpoint but it can only provide the N top runs, not the N bottom ones, so wouldn't be useful for your use case.)