STAT-API

List a MLB team's roster

Grab a team to borrow its id, then list players filtered by team_id — the players endpoint accepts team_id as a filter for both MLB rosters.

  1. 1. Grab one team

    A one-row page gives a valid team id to filter the roster by.

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/mlb/teams?limit=1'
  2. 2. List that team's players

    Filter players by team_id to get the roster.

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/mlb/players?team_id=1'
  3. 3. Print the roster

    console.log("MLB roster")
    console.log(["full_name", "primary_position", "jersey"].join('\t'))
    for (const row of roster) {
      console.log([String(row.full_name ?? ''), String(row.primary_position ?? ''), String(row.jersey ?? '')].join('\t'))
    }