Authenticating¶
To query any sensitive data or to modify competitions you have access to, you will need to authenticate. If you have not done this, you will normally get a 500: Permission Denied
error.
For the majority of APIs, you will need an OpenTrack user account who has meeting director level access to the competition in question. This can be verified by browsing to the Manage | Official
tab of the competition in question.
1. Log in and get a JSON web token¶
import requests
import os
username = os.environ.get("username", "api-test@mailinator.com")
password = os.environ.get("password", "apitest")
BASE_URL = 'https://test-data.opentrack.run/'
r1 = requests.post(BASE_URL + 'api/get-auth-token/', data=dict(username=username,
password=password))
try:
token = r1.json()["token"]
print("Got a token: %s..." % token[0:30])
except KeyError:
print("Unable to authenticate, check credentials")
2. Check authentication with hello API¶
We also provide a simple API call to check you are logged in
r2 = requests.get(BASE_URL + "api/hello/", headers={
"Authorization": "Token " + token
})
print(r2.json())
This will return a dictionary with a simple message like this, depending on your username:
{'message': 'Hello, John Smith <name@email.com>!'}
3. Viewing competitions you can access¶
Competitions for which the current user has permissions can be browsed in a human-friendly form at https://test-data.opentrack.run/api/my-competitions/
This will work for both token authentication and through cookies if a user is logged in through their browser. The unique ID of the competition can be used in the example below to access the results of a unit programmatically
r3 = requests.get(
BASE_URL + "api/my-competitions/?to_date=2026-12-25T12:00:00Z",
headers={"Authorization": "Token " + token}
)
comp = r3.json()['competitions'][-1]
comp_id = comp["id"]
comp_url = comp["url"]
print(comp_id, url)
This will return a structure like the one below:
{
"competitions": [
{
"date": "3000-02-20",
"name": "otrelaydemo - 3000",
"id": "44777e73-d4c3-4a83-84d4-3991ce53edcb",
"url": "/en-gb/x/3000/GBR/ot-team-entry-test/",
"country": "GBR",
"role": "DIRECTOR"
},
{
"date": "2024-12-05",
"name": "Klubbstevne 1 - 2023 - 2024",
"id": "e503bede-70e9-4d39-b22a-058681ae8f38",
"url": "/en-gb/x/2024/NOR/24-ks-12/",
"country": "NOR",
"role": "DIRECTOR"
},
... etc...
}