paginate
paginate<
T>(fetchPage):Promise<T[]>
Defined in: src/helpers/pagination.helpers.ts:93
Collects all results from a paginated endpoint by automatically following cursors.
This function fetches pages until has_more is false. It collects all results
into one array. Use this function when you need all results at once.
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, }));