paginate
paginate<
T>(fetchPage):Promise<T[]>
Defined in: src/helpers/pagination.helpers.ts:119
Collects all results from a paginated endpoint by automatically following cursors.
This function fetches pages until has_more is false or next_cursor is null.
It collects all results into one array. Use this function when you need all results
at once.
This helper does not work around the 10,000-result cap on data source, view, and meeting-notes queries. When a query hits that cap, the result set is truncated and this helper writes a warning. Use collectAllDataSourceRows for those queries.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”fetchPage
Section titled “fetchPage”Function that fetches a single page of results
Returns
Section titled “Returns”Promise<T[]>
Array containing all results from all pages
Example
Section titled “Example”// Get all blocks from a pageconst blocks = await paginate((cursor) => notion.blocks.children.list('page-id', { start_cursor: cursor, page_size: 100 }));
// Get all pages from a database query with filtersconst pages = await paginate((cursor) => notion.databases.query('database-id', { start_cursor: cursor, page_size: 100, filter: filter.status('Status').equals('Active'), }));
// Get all comments on a pageconst comments = await paginate((cursor) => notion.comments.list('page-id', { start_cursor: cursor }));
// Get all users in workspaceconst users = await paginate((cursor) => notion.users.list({ start_cursor: cursor }));
// Search all pagesconst searchResults = await paginate((cursor) => notion.search.query({ query: 'project', filter: { property: 'object', value: 'page' }, start_cursor: cursor, }));