Pull every page of an API into Google Sheets
Most APIs return a page of results, often 100 rows, plus a way to ask for the next page. To get all your data into a sheet you have to follow those pages until they end.
How paging works, and how to script it
- Find the paging style in the API docs: page number, offset and limit, a cursor, a next URL in the body, or a Link header.
- In Apps Script, loop: fetch a page, add its rows to an array, read the next page value, stop when it is empty.
- Sleep a little between calls if the API has a rate limit, and retry on 429 errors.
- Write all rows at once with
setValues; writing one row at a time is slow. - Keep an eye on Google's 6-minute script limit for big pulls.
Sheets API Connector does the paging for you
- Six paging styles: page number, offset/limit, cursor (including Stripe's starting_after), next URL in the body, and Link headers.
- Retries rate limits and flaky gateways with backoff.
- A long import stops in time to save the rows it already has.
Get it, $39 once More about it
I make this tool and sell it.