Variables

$envless->variables->list()

Read one page of variables in an environment

php
/** @return Page<VariableResource> */
public function list(
    string $project,
    string $environment,
    ?int $limit = null,
    ?int $offset = null,
    ?string $product = null,
    int|float|null $timeout = null,
): Page

Fetches one page of the variables in an environment, sorted by name A to Z. Soft deleted variables are excluded.

Every value and defaultValue comes back as ciphertext, because the server holds no key material and cannot decrypt anything. Run each one through Envless::decryptValue() with the workspace passphrase and the workspaceId from $envless->me->get(). Rows written before ciphertext was enforced can still hold plaintext, so test with Envless::isCiphertext() rather than reading a failed decrypt as corruption. Pagination is limit and offset only, and a limit above 100 is rejected with 400 request.invalid_pagination rather than clamped.

Example

php
use Envless\Envless;

$envless = new Envless();

$page = $envless->variables->list('api', 'production', limit: 50);

echo $page->pagination['totalCount'], PHP_EOL;

foreach ($page->items as $variable) {
    echo $variable['name'], PHP_EOL;
}

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug the environment belongs to.
$environmentstringYesEnvironment slug to read variables from.
$limitintNoPage size between 1 and 100.
$offsetintNoNumber of variables to skip before the page starts.
$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

Page<VariableResource> holding items plus a pagination envelope with totalCount and hasMore.

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

  • A project locked by the workspace plan refuses reads as well as writes, with 402 plan.upgrade_required.
  • A duplicate project slug across two products is 409 project.ambiguous_product. Retry with product:.

Required scopes

variables:read

Underlying endpoint

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

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

In TypeScript

envless.variables.list()

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