Handling Paginated API Responses in Google Apps Script

Published: 2021-03-19

Category: Code | Tags: code, code snippet, example, google apps script, how to, programming, tutorial

One of my favorite things about Google Apps Script is that I can get information from an API and write it directly to a shared document or spreadsheet. Information is collected automatically and immediately available to a group of people working on that same doc.

It's not uncommon for these requests to come back in paginated form. Meaning, if your request has 100 responses, they'll come in batches of n size instead of all at once. To demonstrate, I've made a video showing how I use a script to handle requests to Canvas.

If you want to play with it, here's an example you can start from:



I am trying to do the same with Notion API in Google App Script, querying a database of more than 100 items.

In the requests they provide a start_cursor and in the response a has_more boolean value letting you know there is more data as well as a next_cursor parameter that you can use to retrieve the next page of results by passing the value as the start_cursor parameter to the same endpoint.

i just started learning about APIs and don’t really know how to structure this particular example. So far i have code working without any pagination so a hard limit of 100 items.

Do you have any pointers on how to do this or an example?

Comments are always open. You can get in touch by sending me an email at brian@ohheybrian.com