From 54b91f6a633887231cf53e0001b3fe44c3b48540 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Jan 2025 05:43:28 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index fd16ae9..5b0f970 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,39 @@ On timeout, an `APIConnectionTimeoutError` is thrown. Note that requests which time out will be [retried twice by default](#retries). +## Auto-pagination + +List methods in the Zeroentropy API are paginated. +You can use the `for await … of` syntax to iterate through items across all pages: + +```ts +async function fetchAllDocuments(params) { + const allDocuments = []; + // Automatically fetches more pages as needed. + for await (const documentGetInfoListResponse of client.documents.getInfoList({ + collection_name: 'collection_name', + })) { + allDocuments.push(documentGetInfoListResponse); + } + return allDocuments; +} +``` + +Alternatively, you can request a single page at a time: + +```ts +let page = await client.documents.getInfoList({ collection_name: 'collection_name' }); +for (const documentGetInfoListResponse of page.documents) { + console.log(documentGetInfoListResponse); +} + +// Convenience methods are provided for manually paginating: +while (page.hasNextPage()) { + page = await page.getNextPage(); + // ... +} +``` + ## Advanced Usage ### Accessing raw Response data (e.g., headers)