> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  The API key for your account. You can find this in your [account settings](https://squarecloud.app/en/account/security).
</ParamField>

Requires an API key with the `envs:write` [scope](/en/api-reference/authentication#scopes).

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](/en/api-reference/endpoint/workspace/members/invite#roles) or ownership.

If you only need to change a few variables without touching the rest, use [Add/Edit Variables](/en/api-reference/endpoint/apps/envs/add_n_edit) instead, or [Remove Variables](/en/api-reference/endpoint/apps/envs/remove) to delete specific keys.

## Parameters

<ParamField path="app_id" type="string" placeholder="App ID" required>
  The application ID.
</ParamField>

<ParamField body="envs" type="object">
  The key and value variables you want on the environment.
</ParamField>

## Response

<ResponseField name="status" type="string">
  Indicates whether the call was successful: `success` if it was, `error` if not.
</ResponseField>

<ResponseField name="response" type="object">
  The key and value of all environment variables you defined.
</ResponseField>

<ResponseExample>
  ```json theme={"system"}
  {
    "status": "success",
    "response": {
      "TEST": "overwriteTest"
    }
  }
  ```
</ResponseExample>

## Common errors

| Code | HTTP | Meaning |
| - | - | - |
| `STATIC_APP_ENV_NOT_SUPPORTED` | 400 | The application is static; static apps don't support environment variables. |
| `INVALID_ENV_CONTENT` | 400 | `envs` is missing, not an object, or an array. |
| `TOO_MANY_ENV_VARS` | 400 | The new set would exceed 256 environment variables. |
| `ENV_NAME_TOO_LONG` | 400 | A variable key exceeds 1024 characters. |
| `ENV_CONTENT_TOO_LONG` | 400 | A variable value exceeds 4096 characters. |

## Related

* CLI: [`squarecloud app env replace`](/en/cli-reference/environment-variables#squarecloud-app-env-replace)
* SDKs: [`api.apps.envs.replace()`](/en/sdks/js/environment_variables) (JavaScript), [`client.apps.envs.replace()`](/en/sdks/py/environment_variables) (Python), [`c.Apps.Envs.Replace()`](/en/sdks/go/environment_variables) (Go)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.