Sport Data API
Season leaderboard
Pick a season and print its points standings, one table per division.
Goal: print the points standings for the most recent season that has results.
The calls
GET /v1/{sport}/seasons → season_id, season_name, season_year
GET /v1/{sport}/rankings?season_id=…&limit=100 → season_id, division, competitor_id,
competitor_name, points, events_scored, best_finish/seasons is cursor-paged (limit 1 to 100, follow next_page_token). /rankings is a top-N list: it
takes season_id, division and limit (1 to 100, default 10) and has no page token.
A season row can exist before any event is loaded (MASL carries a pre-created future season with zero events). So the program walks seasons newest first and stops at the first one that returns standings.
The program
import os
from collections import defaultdict
import requests
import time
BASE_URL = "https://platform-api.altsportsleagues.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['ASD_API_KEY']}"}
SPORT = "smx" # smx, wsl or masl. hlr has no points, see below.
def get(path: str, **params) -> dict:
while True:
res = requests.get(f"{BASE_URL}{path}", headers=HEADERS, params=params, timeout=65)
if res.status_code == 429: # keys allow 10 requests a minute: wait and retry
time.sleep(int(res.headers.get("Retry-After", "15")))
continue
res.raise_for_status()
return res.json()
def all_rows(path: str, **params):
token = None
while True:
body = get(path, **params, limit=100, **({"page_token": token} if token else {}))
yield from body["data"]
token = body.get("next_page_token")
if not token:
return
seasons = sorted(
all_rows(f"/v1/{SPORT}/seasons"),
key=lambda s: s.get("season_year") or 0,
reverse=True,
)
for season in seasons:
rows = get(f"/v1/{SPORT}/rankings", season_id=season["season_id"], limit=100)["data"]
if not rows:
continue # a season with no scored events yet
print(season.get("season_name") or season["season_id"])
by_division = defaultdict(list)
for row in rows:
by_division[row["division"]].append(row)
for division, standings in by_division.items():
print(f"\n Division {division}")
for place, row in enumerate(standings, start=1):
name = row["competitor_name"] or row["competitor_id"]
print(
f" {place:>3}. {name:<30} {row['points']:>8} pts"
f" ({row['events_scored']} events, best {row['best_finish']})"
)
breakconst BASE_URL = 'https://platform-api.altsportsleagues.ai';
const headers = { Authorization: `Bearer ${process.env.ASD_API_KEY}` };
const SPORT = 'smx'; // smx, wsl or masl. hlr has no points, see below.
type Season = { season_id: string; season_name: string | null; season_year: number | null };
type RankingRow = {
season_id: string;
division: string | null;
competitor_id: string;
competitor_name: string | null;
points: number | string | null;
events_scored: number;
best_finish: number | null;
};
async function get<T>(path: string, params: Record<string, string> = {}): Promise<T> {
const res = await fetch(`${BASE_URL}${path}?${new URLSearchParams(params)}`, { headers });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
return res.json() as Promise<T>;
}
async function* allRows<T>(path: string, params: Record<string, string> = {}) {
let token: string | null | undefined;
do {
const body = await get<{ data: T[]; next_page_token?: string | null }>(path, {
...params,
limit: '100',
...(token ? { page_token: token } : {}),
});
yield* body.data;
token = body.next_page_token;
} while (token);
}
const seasons: Season[] = [];
for await (const s of allRows<Season>(`/v1/${SPORT}/seasons`)) seasons.push(s);
seasons.sort((a, b) => (b.season_year ?? 0) - (a.season_year ?? 0));
for (const season of seasons) {
const { data: rows } = await get<{ data: RankingRow[] }>(`/v1/${SPORT}/rankings`, {
season_id: season.season_id,
limit: '100',
});
if (rows.length === 0) continue; // a season with no scored events yet
console.log(season.season_name ?? season.season_id);
const byDivision = new Map<string, RankingRow[]>();
for (const row of rows) {
const key = row.division ?? '(none)';
byDivision.set(key, [...(byDivision.get(key) ?? []), row]);
}
for (const [division, standings] of byDivision) {
console.log(`\n Division ${division}`);
standings.forEach((row, i) => {
const name = row.competitor_name ?? row.competitor_id;
console.log(
` ${String(i + 1).padStart(3)}. ${name.padEnd(30)} ${row.points} pts` +
` (${row.events_scored} events, best ${row.best_finish})`,
);
});
}
break;
}Watch out
limitcaps the whole response, across divisions. Rows come back ordered byseason_id(an opaque hash, not a date), then division, then points (highest first). With several divisions in one season, a smalllimitcan fill up on the first division and leave the next one out. Passdivision=to get one division's full top N.- No page token. Rankings are computed from
event_resultson each request, so the top 100 is the most you can read in one standings table. hlrreturns404 not_found. High Limit Racing has no points data, so a points standing does not exist for it.GET /v1/hlr/capabilitiesreports the same thing ahead of time. To rank HLR drivers, use finishes from Who won every event instead.- For MASL,
competitor_nameis a team. It can also benullwhen a competitor has no name on file.