---
title: "Update an environment's variable"
url: https://docs.corefinity.com/api/reference/enterprise/update-enterprise-variable
type: endpoint
last_updated: 2026-11-13
feature: enterprise-variables
related:
  - https://docs.corefinity.com/guides/corestack-enterprise/environment-variables.md
---
# Update an environment's variable

Creates the variable when the environment does not have it (`201`), and changes it otherwise (`200`). Leave
`value` out to keep the stored value, so a rename never needs it; a new variable needs one. The answer carries
the mask, never the value.

```http
PUT /api/environments/{environment}/variables/{name}
```

- Scope: `write`
- Two-factor: required on your account (all)
- Rate limit: 20 a minute
- Try it in the console: off. It has not been cleared for the console. Copy the request and run it yourself when you are sure.

## Path parameters

- `environment` (integer, required): The id of a CoreStack Enterprise environment. Not the same number as a site row id.
- `name` (string, required): The variable's name, without the `CF_` prefix builds see it with. A new name is letters, digits and underscores, starting with a letter or underscore, at most 64 characters; a variable the environment already has is found by its stored name as it is, whatever the rules were when it was saved.

## Body

- `rename_to` (string or null): A new name for the variable, which keeps its value unless `value` changes it in the same request: letters, digits and underscores, starting with a letter or underscore, at most 64 characters, and not starting with `CF_` in any case. Null, or the name it already has, renames nothing.
- `value` (string or null): Leave out to keep the stored value. An empty string or null clears it. Any other string sets it, exactly as sent: at most 2,048 characters, with no line breaks, control or invisible formatting characters.

## Request

### curl

```bash
curl -X PUT https://manage.corefinity.com/api/environments/1311/variables/API_TOKEN \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "value": "example-value-not-a-real-secret"
  }'
```

### PHP

```php
use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->put('https://manage.corefinity.com/api/environments/1311/variables/API_TOKEN', [
        'value' => 'example-value-not-a-real-secret',
    ]);

$data = $response->json();
```

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/environments/1311/variables/API_TOKEN', {
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    value: 'example-value-not-a-real-secret',
  }),
});

// An answer with no body (204) has nothing to parse.
const text = await res.text();
const data = text && JSON.parse(text);
```

### Python

```python
import os
import requests

res = requests.put(
    "https://manage.corefinity.com/api/environments/1311/variables/API_TOKEN",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "value": "example-value-not-a-real-secret",
    },
)

data = res.json() if res.content else None
```

## Responses

### 200 The variable after the change.

```json
{
  "variable": {
    "masked": "••••••••cret",
    "name": "API_TOKEN",
    "updated_at": "2026-11-09T10:42:07Z"
  }
}
```

### 201 The variable was created.

```json
{
  "variable": {
    "masked": "••••••••cret",
    "name": "SEARCH_API_KEY",
    "updated_at": "2026-11-09T10:42:07Z"
  }
}
```

### 401 No token, or a token that is not valid.

```json
{
  "message": "Unauthenticated."
}
```

### 403 The token lacks the scope (`scope_required`, with the `scope` to use), or your company requires two-factor authentication and you have not set it up. For routes outside Managed Clusters.

```json
{
  "code": "company_unavailable",
  "message": "Your company is unavailable.",
  "reason": "company_unavailable"
}
```

### 404 The id does not exist, or it is something you cannot see. Both answer the same body.

```json
{
  "message": "Not found."
}
```

### 409 The new name, or `rename_to`, is one another variable of the environment already has (`exists`). Names are compared without case.

```json
{
  "code": "exists",
  "message": "This environment already has a variable with that name.",
  "reason": "exists"
}
```

### 422 The request was refused and nothing was stored. `errors` names the field. - `variable_invalid` on `name` or `rename_to`: the name is not letters, digits and underscores starting with a letter or underscore, is longer than 64 characters, or starts with `CF_`. - `variable_invalid` on `value`: a new variable without a value, a value longer than 2,048 characters, or one with a line break, control or invisible formatting character. - `variable_reserved` on `name` or `rename_to`: a name CoreStack sets itself. - `variable_tool_credential` on `name` or `rename_to`: a name a build tool reads its own credentials from, such as `NPM_TOKEN` or `COMPOSER_AUTH`. - `too_many_variables` on `name`: the environment holds as many variables as it can. - `invalid`: a field of the wrong type, a field this endpoint does not take, or an environment that belongs to a CoreStack or CoreCluster site (on `environment`).

```json
{
  "code": "variable_invalid",
  "errors": {
    "name": [
      "Use letters, digits and underscores, starting with a letter or underscore, without the CF_ prefix (CoreStack adds it)."
    ]
  },
  "message": "Use letters, digits and underscores, starting with a letter or underscore, without the CF_ prefix (CoreStack adds it).",
  "reason": "variable_invalid"
}
```

### 429 Too many requests (`rate_limited`). Wait for the number of seconds in `Retry-After`, which `retry_after_seconds` repeats.

```json
{
  "code": "rate_limited",
  "message": "Too many requests. Try again in 60 seconds.",
  "reason": "rate_limited",
  "retry_after_seconds": 60
}
```

## If it is refused

| Status | Reason | What to do |
|---|---|---|
| 401 |  | Send a valid token as `Authorization: Bearer <token>`. |
| 403 | `company_unavailable` | Your company is unavailable. |
| 403 | `scope_required` | Use a token with the scope named in `scope`. |
| 403 | `two_factor_required` | Turn on two-factor on your account, then send again. |
| 404 |  | Check the id. You see only what your account can reach. |
| 409 | `exists` | It already exists. Use the existing one. |
| 422 | `variable_invalid` | Use letters, digits and underscores, starting with a letter or underscore, without the CF_ prefix (CoreStack adds it). |
| 422 | `variable_reserved` | CF_DOMAIN is set by CoreStack. Choose another name. |
| 422 | `invalid` | Fix the field named in `field`; `errors` says why. |
| 422 | `too_many_variables` | This environment already has the most variables it can hold. |
| 422 | `variable_tool_credential` | Builds see the variable under another name, so the tool it is meant for never reads it. Add the credentials under Deployments, Private registries, instead. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |

## The same task elsewhere

- Guide: [Environment variables](https://docs.corefinity.com/guides/corestack-enterprise/environment-variables.md)
