STAT-API

Paginate by hand with from_id

Pagination is keyset, not offset. Each list response returns next_from_id — the cursor for the following page — and null on the last page. This is the loop the auto-paging iterator runs for you, written out by hand.

  1. 1. Follow next_from_id until it is null

    The first request omits from_id; each subsequent one passes the previous page's next_from_id.

    let fromId: number | undefined = undefined
    let total = 0
    let pageNum = 0
    for (;;) {
      const page = await api.nba.teams.list({ limit: 100, from_id: fromId })
      pageNum += 1
      total += page.teams.length
      console.log(`page ${pageNum}: ${page.teams.length} rows, next cursor = ${page.next_from_id ?? 'none'}`)
      if (page.next_from_id === null) break
      fromId = page.next_from_id
    }
    console.log(`walked ${total} teams across ${pageNum} pages by hand`)