API: seperate runs by subcategory
3 years ago
Tennessee, USA

Hi! I am messing around with the SRC APi, Is there a way to get runs on the IL board and separate them by subcategory? The game is BotW

Israel
  1. If you want to get ALL runs of a certain game and category (which means also getting obsolete runs), use the "GET /runs" endpoint: https://github.com/speedruncomorg/api/blob/master/version1/runs.md#get-runs

You can filter by the game and category (and level for ILs) (and probably status for only verified runs). After getting the results, you can split the runs by the values of the subcategory variable (inside the "values" property). You can get a list of variables for categories in the "GET /categories/{id}/variables" endpoint: https://github.com/speedruncomorg/api/blob/master/version1/categories.md#get-categoriesidvariables

  1. If you want to get only the latest runs in the board (which means verified non-obsolete runs), use the Leaderboards endpoint, which also groups and sorts the runs by places. You can get runs by full-game categories or IL categories. https://github.com/speedruncomorg/api/blob/master/version1/leaderboards.md#leaderboards

Instead of getting all results and splitting by the variable, you will have to do multiple calls to the API (one for each subcategory). In each call you filter by the relevant subcategory variable value.

Edited by the author 3 years ago
Gaming_64 likes this
Tennessee, USA

So what URL would I use get on? Say the game id is abc345, the level id is 345abc and the variable (subcategory) is 678def I’ve just started using the API so I’m not 100% sure what to do with the endpoints and stuff

Israel

That depends on how you intend to call the API. If it's just a direct call for testing in the browser, you can do something like this: https://www.speedrun.com/api/v1/leaderboards/9dowp9k1/category/n2yooy7d?var-yn217z28=zqo22g5l

Game "9dowp9k1" is "Mr. Bree Returning Home" Category "n2yooy7d" is "NG+" Variable "yn217z28" is the "NG+ mode" subcategory variable The value "zqo22g5l" is the "reversed" subcategory

Edited by the author 3 years ago
Gaming_64 likes this
Tennessee, USA

Hmm thanks; I’ll try this later! (Also, I am using node-fetch) Edit: also, what does “reversed subcategory” do and how do I get it?

Edited by the author 3 years ago
Israel

This is just a name. In this game there are also "normal" and "hardcore" subcategories. Don't forget that you can define variables with any name and values.

Edited by the author 3 years ago
Gaming_64 likes this
Tennessee, USA

:I sorry about that lol, didn't see the quotation marks

Edit: https://www.speedrun.com/api/v1/leaderboards/76rqjqd8/level/y9mj6ml9/824mrqg2?var-rqv6j27 still returns all the ILs, not just the one under the subcat

Edited by the author 3 years ago
Israel

That because you didn't filter anything. Url query parameters go as "name=value".

In your case, you need: var-{variable name}={variable value}

Edited by the author 3 years ago
Gaming_64 likes this
Tennessee, USA

Wait I’m confused now (sorry for all the late replies, also thanks for your help this far) Let me provide context: The game Breath of the Wild has levels for all the mini-dungeons across the map. The levels are grouped across map regions, so you go to, say “Great Plateau Shrines”, and you can select the individual dungeons from there.

I don’t understand the difference between Variable Name and Value. I only see one list when calling /api/v1/levels/xxxxxx/variables (as far as I know, I’ll look at it later again to make sure)

Israel

Okay, I entered the Breath of the Wild leaderboard for the first time. Let's take "Dueling Peaks Shrines" IL as an example, and the Any% category.

Game ID: 76rqjqd8 (source: https://www.speedrun.com/api/v1/games?name=Breath%20of%20the%20wild ) Level ID: 5d7v1j5d (source: https://www.speedrun.com/api/v1/games/76rqjqd8/levels )

Categories for this game: https://www.speedrun.com/api/v1/games/76rqjqd8/categories The ID for the "Any%" category of per-level type is 824mrqg2.

Variables can be listed under the entire category, or under specific levels. In this case, it's the latter. To find the variables for this level: https://www.speedrun.com/api/v1/levels/5d7v1j5d/variables You will see one variable, with the id "38doz7zl" and name "Dueling Peaks Shrines".

The list of possible values for that variable is under the "values" property. For example, the first value in that list (in json mode) is: "4qy5km41":{"label":"Bosh Kala","rules":null,"flags":{"miscellaneous":false}} So you know its ID is 4qy5km41. The ID of "Ha Dahamar" subcategory is 5q82n3gq, an so on.

As per the API documentation, you will have to use this endpoint and filter: GET /leaderboards/{game}/level/{level}/{category}?var-{subcategory variable name}={subcategory variable value} to get the leaderboard of a specific game, specific level, specific category, and specific subcategory.

So, in this example, to get the leaderboard of the "Bosh Kala" subcategory under the Any% category under the level "Dueling Peaks Shrines", you will have to use everything we learned so far:

https://www.speedrun.com/api/v1/leaderboards/76rqjqd8/level/5d7v1j5d/824mrqg2?var-38doz7zl=4qy5km41

Edited by the author 3 years ago
Gaming_64, TheEskot, and Komali like this
Tennessee, USA

IT WORKS!!!! Thank you so much for sticking through this with me!