FIRST Inspires api can't get champs division matches

So, getting the matches for any event besides champs divisions works great:

auth = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

import requests

url = "https://frc-api.firstinspires.org/v3.0/2023/matches/scand?tournamentLevel=Qualification"

payload={}
headers = {
  'Authorization': f'Basic {auth}',
  'If-Modified-Since': ''
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

but when I try this:

auth = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

import requests

url = "https://frc-api.firstinspires.org/v3.0/2023/matches/cur?tournamentLevel=Qualification"

payload={}
headers = {
  'Authorization': f'Basic {auth}',
  'If-Modified-Since': ''
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

I get this error here:

Invalid Event Requested : No event was found using the Season 2023 and Event Code cur

am I using the API wrong?

Have you tried the event codes listed here?

3 Likes

that worked. For some reason, the champs division codes that I’m getting from the statbotics api are different than the ones here.

TBA elected to use more rational division codes which, unfortunately, has the adverse effect of breaking things that use the API with FIRST’S official codes.

Is there a way to get the event codes straight from FIRST?

Keep in mind you can also get the FIRST Event Code from TBA by querying the TBA event and looking for the first_event_code key.

As for FIRST’s stuff, event list for the season, then filter by Tournament Type being ChampionshipDivision / ChampionshipSubdivision I suspect is the easiest programmatic way.

1 Like

If Statbotics is using the TBA API and their event codes, you’ll need to use those in your application. If you want to call data directly from the FIRST API, you can use FIRST’s codes.

How do you query the TBA event, is there an API that I can use with python?

TBA has quite a few libraries available to get data from it, but it’s a third party site that rehosts FIRST data and provides insights / analysis / aggregation past what FIRST formally endorses / permits / supports. You can also just use normal HTTP requests with no extraneous libraries.

expand for example
import requests

baseURL = 'http://www.thebluealliance.com/api/v3/'
header = {'X-TBA-Auth-Key':'(insert auth key here)'} 

def getTBA(url):
	return requests.get(baseURL + url, headers=header).json()

def getAllTeams(urlarg):
	teams = []
	currentPage = 0
	currentTeams = getTBA("teams/" + str(currentPage) + str(urlarg))
	for team in currentTeams:
		teams.append(team)
	while currentTeams != []:
		currentPage+=1
		currentTeams = getTBA("teams/" + str(currentPage) + str(urlarg))
		for team in currentTeams:
			teams.append(team)

	return teams

Jared provided context for comparison, and I wanted to make sure that the mention of TBA wasn’t super confusing.

To do it with FIRST’s official tooling, you’d want to use this API call most likely, and pay attention to the attribute of tournamentType.

1 Like