Rank NBA season leaders

season_player_stats holds one row per player per season. Page through the whole season with the keyset cursor, then sort client-side to build any leaderboard.

  1. 1. Fetch the first page

    Filter to a season and set a page size. The response envelope wraps the rows with limit and next_from_id.

    curl -sS \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/nba/season_player_stats?season_id=2027&limit=50'
  2. 2. Walk the keyset cursor

    Pass the previous response's next_from_id back via from_id to get the next page; a null next_from_id marks the final page.

    curl -sS \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/nba/season_player_stats?season_id=2027&limit=50&from_id=NEXT_FROM_ID'
  3. 3. Rank by points

    Accumulate every page, then sort by any numeric column — here, points.

    const headers = { Authorization: 'Bearer YOUR_API_KEY' }
    const base = 'https://api.stat-api.com/api/v1/nba'
    
    // Page through the whole season with the keyset cursor.
    const rows: any[] = []
    let fromId: number | null = null
    do {
      const url = new URL(`${base}/season_player_stats`)
      url.searchParams.set('season_id', '2027')
      url.searchParams.set('limit', '200')
      if (fromId) url.searchParams.set('from_id', String(fromId))
      const page = await fetch(url, { headers }).then(r => r.json())
      rows.push(...page.season_player_stats)
      fromId = page.next_from_id
    } while (fromId)
    
    // Top of the league by points.
    rows.sort((a, b) => b.pts - a.pts)