def update_by_id(
id: str,
patch: VariablePatch,
*,
timeout: float | None = None,
) -> VariableResourceasync def update_by_id(
id: str,
patch: VariablePatch,
*,
timeout: float | None = None,
) -> VariableResourcePatches one variable by id, with the same body and the same semantics as update. This is the better call for a sync client that already tracks ids, since it survives renames and needs no project or environment lookup.
value and defaultValue must be ciphertext when present, None clears defaultValue, and omitting a field leaves it untouched.
Note the ordering quirk, which is the reverse of the name addressed route: the variable is looked up before the ciphertext is validated, so a malformed value against an unknown id returns 404 rather than 400.
Example
from envless import envless
variable = envless.variables.update_by_id(
'a7f2c1e0-8b4d-4c11-9f3a-2d5e6b7c8d90',
{'required': False},
)
print(variable['name'], variable['required'])import asyncio
from envless import AsyncEnvless
async def main() -> None:
async with AsyncEnvless() as envless:
variable = await envless.variables.update_by_id(
'a7f2c1e0-8b4d-4c11-9f3a-2d5e6b7c8d90',
{'required': False},
)
print(variable['name'], variable['required'])
asyncio.run(main())Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | str | Yes | Variable id from a list response or a webhook payload. |
patch['name'] | str | No | New name, matching ^[A-Za-z_][A-Za-z0-9_]*$ and 1 to 100 characters, rejected with 409 when another live variable holds it, compared without regard to case. |
patch['value'] | str | No | Replacement ciphertext from encrypt_value, prefixed v1: or v2:. |
patch['type'] | str | No | One of the VARIABLE_TYPE values. |
patch['isSecret'] | bool | No | Marks or unmarks the variable as a secret, which the example feed reports as secret. Stored, but not echoed in the response. |
patch['visibility'] | str | No | One of the VARIABLE_VISIBILITY_LEVELS values. |
patch['required'] | bool | No | Toggles whether the variable is required for the environment. |
patch['defaultValue'] | str | None | No | Replacement ciphertext fallback, or None to clear it. |
timeout | float | No | Seconds each attempt of this call may take, the response body included, before it raises EnvlessNetworkError with is_timeout set. Overrides the client's timeout for this call, and 0 turns the limit off. |
Returns
VariableResource for the patched variable, values still ciphertext.
Worth knowing
- This route is the only rename path that does not depend on knowing the project and environment slugs.
- A rename is checked locally before anything is sent. The new name must be 1 to 100 characters of letters, numbers and underscores, and it must not start with a number. Case is kept exactly as you type it, and a local refusal raises
EnvlessApiErrorcarryingrequest.body_invalid.
Required scopes
variables:write
Underlying endpoint
PATCH /variables/{id}
Request and response schema, every error code, and a live playground.
In TypeScript
envless.variables.updateById()
The same method in @goenvless/sdk, with the same request, retries and errors.