/** @return VariableResource */
public function getById(string $id, int|float|null $timeout = null): arrayReads 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
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
| Parameter | Type | Required | Description |
|---|---|---|---|
$id | string | Yes | Variable id from a list response or a webhook payload. |
$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
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
producthint 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.