List a NFL 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 NFL rosters.
1.Grab one team
A one-row page gives a valid team id to filter the roster by.
const teams = (await api.nfl.teams.list({ limit: 1 })).teamsThe complete program
Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.
import { StatApi } from '@stat-api/client'
const api = new StatApi() // reads STAT_API_KEY from the environment
// Grab one team
const teams = (await api.nfl.teams.list({ limit: 1 })).teams
// List that team's players
const roster = (await api.nfl.players.list({ team_id: teams[0].id })).players
// Print the roster
console.log("NFL 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'))
}