Skip to content

    iterItems

    Process one record at a time across a cursor-based list. For example, iterate through all brands without tracking the next cursor yourself.

    Signature

    iterItems<O extends { cursor?: string }>(
      fetchPage: (options: O) => Promise<ApiResponse<unknown>>,
      options: O,
    ): AsyncGenerator<unknown>

    Parameters

    fetchPage
    A function that accepts your filters and cursor and returns the SDK response for one page. Call a list method that returns meta.next_cursor.
    options
    The initial filters and optional cursor. Each subsequent request keeps the same filters.

    Return value

    An async generator of individual records. It calls paginate to fetch each page and itemsOf to read the records.

    Errors

    • AeoError if the API repeats a cursor or still has another page after 10,000 pages. Errors from fetchPage also reach the caller.

    TypeScript example

    import { iterItems } from "@aeoapi/aeo-sdk";
    import { AeoClient } from "@aeoapi/aeo-sdk";
    
    const apiKey = process.env.AEO_API_KEY;
    if (!apiKey) throw new Error("Set AEO_API_KEY on your server.");
    const client = new AeoClient(apiKey, { baseUrl: "https://api.aeoapi.dev" });
    
    const fetchBrands = (options: { limit?: number; cursor?: string }) =>
      client.v2GetBrands(options);
    for await (const brand of iterItems(fetchBrands, { limit: 25 })) {
      console.log(brand);
    }

    See TypeScript client setup for authentication, timeouts and retry settings.