/** @return \Generator<int, KeyResource, mixed, void> */
public function iterate(
?int $limit = null,
?int $offset = null,
?string $search = null,
?string $order = null,
int|float|null $timeout = null,
): \GeneratorReturns a Generator that yields keys individually and fetches the next page only once the current one is drained. Breaking out of the loop stops the requests, which makes this the cheapest way to resolve a single prefix to a full row.
The generator defaults to the maximum page size of 100 and clamps anything larger, so limit: only ever makes pages smaller. Since a workspace holds at most 100 live keys, one page normally covers everything.
Creating or revoking keys while you iterate changes the set that offsets are counted against, so a key can be skipped or repeated. Collect the ids you care about first, then act on them after the loop has finished.
Example
use Envless\Envless;
$envless = new Envless();
foreach ($envless->keys->iterate() as $key) {
if ($key['prefix'] === 'ev_sk_9fQ2xa') {
echo $key['id'], ' ', implode(', ', $key['projectIds']), PHP_EOL;
break;
}
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$limit | int | No | Page size per request, capped at 100 and defaulting to 100. |
$offset | int | No | Row the walk starts at, advancing by the number of items each page returns. |
$search | string | No | Case insensitive substring match against name and prefix. |
$order | string | No | Defaults to name, which sorts A to Z. Pass asc for oldest first or desc for newest first on createdAt. |
$timeout | int|float | No | Seconds 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
Generator<int, KeyResource> yielding one key per step.
Reads the keys 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
- The generator is lazy, so no request is sent until you start consuming it.
- Yielded rows carry
prefixand neversecret, so scanning cannot recover a lost credential.
Required scopes
keys:read
Underlying endpoint
GET /keys
Request and response schema, every error code, and a live playground.
In TypeScript
envless.keys.iterate()
The same method in @goenvless/sdk, with the same request, retries and errors.