Variables

$envless->variables->iterateHistory()

Stream a variable audit trail newest first

php
/** @return \Generator<int, VariableHistoryEvent, mixed, void> */
public function iterateHistory(
    string $project,
    string $environment,
    string $name,
    ?int $limit = null,
    ?int $offset = null,
    ?string $product = null,
    int|float|null $timeout = null,
): \Generator

Returns a Generator over the audit trail for a variable, fetching the next page only when the current one runs out. Nothing is requested until you begin consuming it.

Breaking out of the loop ends the walk, which makes this the cheap way to scan back to a known point in time. Because new events land at the front of the ordering, a write during a long walk shifts the window and can repeat an event you already saw.

Example

php
use Envless\Envless;

$envless = new Envless();

$events = $envless->variables->iterateHistory(
    'api',
    'production',
    'STRIPE_SECRET_KEY',
);

foreach ($events as $event) {
    if ($event['type'] === 'updated') {
        echo $event['createdAt'], ' ', $event['actor']['email'] ?? '', PHP_EOL;
    }
}

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug the environment belongs to.
$environmentstringYesEnvironment slug the variable lives in.
$namestringYesName of a live variable, matched without regard to case.
$limitintNoPage size for each underlying request, clamped to 100.
$offsetintNoOffset the walk starts from, defaults to 0.
$productstringNoProduct slug, needed when the project slug is not unique in the workspace.
$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

Generator<int, VariableHistoryEvent> yielding one audit record per iteration.

Reads the events 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

  • Event types are created, updated, deleted and restored, so filter on those rather than on dotted names.
  • On the Free plan only the latest event is yielded (the API's historyLimited and hiddenCount flags are not surfaced by the iterator, so a single event on Free is the plan, not an empty history); the full trail needs Dev or above.

Required scopes

variables:read

Underlying endpoint

GET /projects/{slug}/environments/{environmentSlug}/variables/{name}/history

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

In TypeScript

envless.variables.iterateHistory()

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