Replace all environment variables
Replace an application’s whole environment with PUT /v2/apps/:app_id/envs: variables not in the body are deleted, and an empty envs object wipes all.
PUT
Replace all environment variables
string
required
The API key for your account. You can find this in your account settings.
envs:write scope.
Overwrite replaces the application’s entire environment with exactly the variables you send: anything already set that isn’t included in the request body is deleted. Sending an empty envs object wipes every variable, which makes this the endpoint to use for a full reset rather than an incremental change.
The same limits as other environment variable endpoints apply: up to 256 variables per application, 1024 characters per key, 4096 per value. Static applications aren’t supported and return an error, and on workspace-shared applications the caller needs the admin role or ownership.
Your application loads its variables with a shell, so a value with spaces or shell characters (such as & or ;) is stored single-quoted, as the dashboard does, and returned that way; a value you already quoted is kept as sent. A reference to another variable ($HOST, ${HOST}, alone or inside double quotes) keeps working, while command substitution ($(...) or backticks) is always stored as plain text. Names are letters, digits, underscores, dots and hyphens, not starting with a digit. Since the whole set is sent, a variable already stored under an invalid name (with a space, or starting with a digit) makes the request answer INVALID_ENV_CONTENT: rename it in the request.
If you only need to change a few variables without touching the rest, use Add/Edit Variables instead, or Remove Variables to delete specific keys.
Parameters
string
required
The application ID.
object
The key and value variables you want on the environment.
Response
string
Indicates whether the call was successful:
success if it was, error if not.object
The key and value of all environment variables you defined.
Common errors
Related
- CLI:
squarecloud app env replace - SDKs:
api.apps.envs.replace()(JavaScript),client.apps.envs.replace()(Python),c.Apps.Envs.Replace()(Go)

