Skip to content

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.

T

PaginatedFetchFunction<T>

Function that fetches a single page of results

Promise<T[]>

Array containing all results from all pages

// Get all blocks from a page
const blocks = await paginate((cursor) =>
notion.blocks.children.list('page-id', { start_cursor: cursor, page_size: 100 })
);
// Get all pages from a database query with filters
const 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 page
const comments = await paginate((cursor) =>
notion.comments.list('page-id', { start_cursor: cursor })
);
// Get all users in workspace
const users = await paginate((cursor) =>
notion.users.list({ start_cursor: cursor })
);
// Search all pages
const searchResults = await paginate((cursor) =>
notion.search.query({
query: 'project',
filter: { property: 'object', value: 'page' },
start_cursor: cursor,
})
);