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.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
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`)The 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
// Follow next_from_id until it is null
let fromId: number | 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`)