STAT-API

Build an NHL box score

A box score is one game plus the per-player stat lines for both teams. Find a game in the current season, fetch its player stats, and group them by team.

  1. 1. Resolve the current season

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/nhl/seasons?limit=200'
  2. 2. Find a game

    List one game from the season; each row carries home/away team ids and the score.

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/nhl/games?season_id=2025&limit=1'
  3. 3. Pull per-player stats for that game

    game_player_stats is keyed by game_id — one row per player who appeared, each carrying team_id and player_id.

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/nhl/game_player_stats?game_id=1'
  4. 4. Split the stat lines into the two teams

    Group by team_id to render the two halves of the box score.

    const by_team = new Map<number, NHLGamePlayerStat[]>()
    for (const row of stats) {
      const bucket = by_team.get(row.team_id) ?? []
      bucket.push(row)
      by_team.set(row.team_id, bucket)
    }
  5. 5. Render both halves of the box score

    console.log(JSON.stringify(Object.fromEntries(by_team), null, 2))