Filtering by two or more seasons with RobotEvents API

I am attempting to fetch a list of events in the UK for the current VRC and VIQRC seasons. Their IDs are 180 and 181.

This seems possible on the RobotEvents API reference.

Screenshot 2024-02-17 at 23.30.15

I have interpreted “array[integer]” above as [180, 181] in code. As such, I have implemented it as follows in Python:

endpoint = "https://www.robotevents.com/api/v2/events"

headers = {
    "accept": "application/json",
    "Authorization": auth_key
}

params = {
    "region": "United Kingdom",
    "season": [180, 181]
}

response = requests.get(endpoint, headers=headers, params=params)
data = response.json()
print(data)

However, the response is always of one or the other. If 180 is before 181 in the array, all the results will be from Full Volume. If 181 is before 180 in the array, all the results will be from Over Under.

The simple workaround is making two GET requests, one after the other, for each season. But it would be preferable to fetch the full list in one request. Has anybody encountered this before? Have I misinterpreted the reference?

I have already discovered that the API is full of quirks and this might be yet another.

2 Likes

Hello.

I fiddled around with this issue for a while, and I stumbled upon this anomaly:

When using the “try it out” feature on the Robot Events website, I noticed that the generated URL was different then the one we created (using requests.get()). The Robot Events URL looked like this:

https://www.robotevents.com/api/v2/events?season%5B%5D=180&season%5B%5D=181&region=United%20Kingdom&myEvents=false

And ours looked like this: ( we can see what ours was by accessing the .url member of our response ( as in response.url )

https://www.robotevents.com/api/v2/events?region=United+Kingdom&season=180&season=18

The biggest difference I could see between the two was the absence of the %5B%5D

  • %5B corresponds to [
  • %5D corresponds to ]

Which means we simply need to change the "season" to "season[]"

As in:

import json
import requests

endpoint = "https://www.robotevents.com/api/v2/events"
auth_key = "Lol, this is a totally valid key XD"

headers = {
    "accept": "application/json",
    "Authorization": "Bearer " + auth_key
}

params = {
    "region": "United Kingdom",
    "season[]": [180, 181],
}

# Make the GET request
response = requests.get(endpoint, headers=headers, params=params)
data = json.dumps(response.json(), indent=4)

file = open("out.json", 'w')
file.write(data)
print(data)
print(response.url)



9 Likes

This worked perfectly. Thank you very much for the solution and the explanation!

1 Like

Np. :+1:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.