league-trac API

league-trac API
StompingBear APIs

Sports data API covering NBA, NHL, MLB, and NFL. Provides player lookups by jersey number, team information, upcoming game schedules, and per-user team preferences.

Base URL: https://api.league-trac.com    Interactive Docs → OpenAPI Spec → Auth Token Setup →

Authentication

All endpoints except /health, /get_logo, and /docs require a Bearer token.

Authorization: Bearer <token>
  • Tokens issued by Authentik, expire after 10 minutes
  • Obtain a token: auth-token league-trac
  • Config: ~/.config/auth-token.env - set AUTHENTIK_URL and LEAGUE_TRAC_CLIENT_ID

Supported Leagues

nba nhl mlb nfl

Endpoints

System

MethodPathAuthDescription
GET/healthNoPublic health check (uptime monitoring)
GET/internal/healthYesDetailed health: DB status, latency, uptime, user
GET/debug/whoamiYesReturns auth context (user, claims)

Players

MethodPathDescription
GET/player/{league}/{jersey}Player from user's preferred team by jersey number. Optional ?search_name= to override team.
GET/player/{league}/{team_code}/{jersey}Player by explicit team code + jersey. e.g. /player/nhl/pit/87
GET/active_player/{league}/{jersey}Active player from user's favorite team.
GET/active_opposition_player/{league}/{jersey}Player from the team that last played against user's favorite team.
GET/search_players?name={last_name}Search by last name. Optional: ?league=nhl, ?first_name=jack. Returns match_type (exact/partial) + results array.

Teams

MethodPathDescription
GET/team_codes/{league}All team codes for a league. Returns array of {team_code, team_location, team_name}.

Preferences

MethodPathDescription
GET/get_preferencesReturns {nba_favorite, nhl_favorite, mlb_favorite, nfl_favorite} (full team names).
PUT/set_preferencesBody: {"nba_favorite":"lakers","nhl_favorite":"rangers",...}. Returns resolved full team names. Errors on no match or multiple matches.
GET/get_preferred_api_team_id/{league}Returns {api_team_id, team_code} for user's preferred team in that league.

Games

MethodPathDescription
GET/get_upcoming?days=4&date=YYYY-MM-DDUpcoming games based on preferences. MLB/NBA/NHL: favorite team only. NFL: all Thu/Sat/Mon games + Sunday games for favorite team.

Assets

MethodPathAuthDescription
GET/get_logo/{league}/{location}/{name}NoReturns SVG team logo. e.g. /get_logo/nba/LosAngeles/Lakers

Admin

MethodPathDescription
POST/admin/cleanup_games?days=2&dry_run=falseDelete game records older than N days. Use dry_run=true to preview.

Example Requests

# Get a token
TOKEN=$(auth-token league-trac)

# Upcoming games (next 7 days)
curl -H "Authorization: Bearer $TOKEN" \
  "https://api.league-trac.com/get_upcoming?days=7"

# Player by preferred team + jersey
curl -H "Authorization: Bearer $TOKEN" \
  "https://api.league-trac.com/player/nba/23"

# Player by explicit team + jersey
curl -H "Authorization: Bearer $TOKEN" \
  "https://api.league-trac.com/player/nhl/pit/87"

# Opponent player lookup
curl -H "Authorization: Bearer $TOKEN" \
  "https://api.league-trac.com/active_opposition_player/nhl/7"

# Search players by last name
curl -H "Authorization: Bearer $TOKEN" \
  "https://api.league-trac.com/search_players?name=hughes&league=nhl"

# Set preferences
curl -X PUT -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"nba_favorite":"lakers","nhl_favorite":"rangers"}' \
  "https://api.league-trac.com/set_preferences"

# All NHL team codes
curl -H "Authorization: Bearer $TOKEN" \
  "https://api.league-trac.com/team_codes/nhl"

Error Codes

StatusMeaning
400Bad request - missing or invalid parameter
401Missing or invalid Bearer token
404Player, team, or preference not found
503Service degraded - database unreachable

Contact

Email: [email protected]
License: Internal / Partner Use Only