Products

$envless->products->iterate()

Stream products one at a time

php
/** @return \Generator<int, ProductResource, mixed, void> */
public function iterate(
    ?int $limit = null,
    ?int $offset = null,
    ?string $search = null,
    ?string $order = null,
    int|float|null $timeout = null,
): \Generator

A Generator that yields products one by one and requests the next page only when the current one is exhausted. Nothing is fetched until the first iteration, and breaking out of the loop ends the walk with no further requests.

The walk advances the offset by the number of rows it received, so products created or deleted while you iterate can move the window and cause a row to repeat or be skipped. Treat each page as a snapshot rather than a consistent view of the workspace.

Example

php
use Envless\Envless;

$envless = new Envless();

foreach ($envless->products->iterate(order: 'asc') as $product) {
    echo $product['slug'], PHP_EOL;
}

Parameters

ParameterTypeRequiredDescription
$limitintNoPage size for each underlying request, capped at 100.
$offsetintNoRow to start the walk from.
$searchstringNoCase-insensitive substring match against product name and slug.
$orderstringNoDefaults to name, which sorts A to Z. Pass asc for oldest first or desc for newest first on createdAt.
$timeoutint|floatNoSeconds each attempt of this call may take, the response body included, before it throws Envless\Exception\NetworkException with isTimeout() true. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

An Generator<int, ProductResource> that yields each product in turn.

Reads the products collection. list returns one page as an Envless\Result\Page with items and pagination, listAll collects every page into an array, and iterate returns a Generator that yields one item at a time, fetching the next page only when the loop gets there.

Worth knowing

  • This is the only list variant that keeps memory flat, since at most one page is held at a time.

Required scopes

products:read

Underlying endpoint

GET /products

Request and response schema, every error code, and a live playground.

In TypeScript

envless.products.iterate()

The same method in @goenvless/sdk, with the same request, retries and errors.