Variables

$envless->variables->getById()

Read one variable by id

php
/** @return VariableResource */
public function getById(string $id, int|float|null $timeout = null): array

Reads one live variable by id, without needing to know which project or environment it belongs to. Ids never change, so this is the stable address for sync clients and for ids arriving in webhook payloads, while get is the one to use when you know the environment and the human name.

The lookup is scoped to the workspace behind the key and joins through the environment and project, so a soft deleted variable, or one whose environment or project was deleted, is invisible and answers 404.

The response identifies its home only through environmentId. There is no project or environment slug in it, so keep your own mapping if you need to build a name addressed call afterwards.

Example

php
use Envless\Envless;

$envless = new Envless();

$id = 'a7f2c1e0-8b4d-4c11-9f3a-2d5e6b7c8d90';
$variable = $envless->variables->getById($id);

echo "{$variable['name']} {$variable['environmentId']}", PHP_EOL;

Parameters

ParameterTypeRequiredDescription
$idstringYesVariable id from a list response or a webhook payload.
$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

VariableResource for that id, with ciphertext value and defaultValue.

Worth knowing

  • Existence is checked before the project restriction, so a 403 from a project restricted key confirms the variable exists.
  • No product hint is needed on the id routes, the lookup already resolves through the workspace.

Required scopes

variables:read

Underlying endpoint

GET /variables/{id}

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

In TypeScript

envless.variables.getById()

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