# Organization API: Organization deployments: Variables

> The 7 Organization API operations for variables.

Source: https://www.coritan.com/docs/api/reference/organizations/organization-deployments/deployments-variables/

Part of [Organization deployments](/docs/api/reference/organizations/organization-deployments/).

## Operations

| Method | Path | Summary |
| --- | --- | --- |
| GET | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables`](#op-get-api-v1-orgs-org-slug-deployments-deployment-uuid-variables) | List variables |
| PUT | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables`](#op-put-api-v1-orgs-org-slug-deployments-deployment-uuid-variables) | Set or replace variables |
| GET | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/export`](#op-get-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-export) | Export variables |
| POST | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/import`](#op-post-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-import) | Import a .env file into one environment (and branch) |
| GET | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/resolved`](#op-get-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-resolved) | Resolved variables |
| PUT | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/{key}`](#op-put-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-key) | Set a variable |
| DELETE | [`/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/{key}`](#op-delete-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-key) | Delete one variable of one environment |

### List variables {#op-get-api-v1-orgs-org-slug-deployments-deployment-uuid-variables}

`GET /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables`

List a deployment's variables without their values, by environment,
branch and key, and the env groups linked to it. ``environment`` and
``branch`` narrow the list; ``hint`` is the last four characters of a
value of eight or more.

#### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |  |
| `org_slug` | path | string | yes |  |
| `environment` | query | string or null | no | Only this environment's: all, production, preview or development |
| `branch` | query | string or null | no | Only the ones set for this preview branch |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |

### Set or replace variables {#op-put-api-v1-orgs-org-slug-deployments-deployment-uuid-variables}

`PUT /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables`

Set many variables in one environment (and, for ``preview``, one
branch); a variable given without ``value`` keeps its saved one. With
``replace`` every variable of that environment and branch not listed
is deleted. Changes reach the deployment with its next release.

#### Parameters

| Name | In | Type | Required |
| --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |
| `org_slug` | path | string | yes |

#### Request body

`application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `environment` | string | no |  |
| `branch` | string or null | no | Preview only: the branch the values apply to |
| `vars` | array of VariableIn | yes |  |
| `vars[].key` | string | yes |  |
| `vars[].value` | string or null | no | Left out: the saved value is kept |
| `vars[].secret` | boolean or null | no | Withheld from exports and redacted from build logs; new variables default to true |
| `vars[].target` | string or null | no |  |
| `replace` | boolean | no | Delete every variable of this environment and branch not in vars |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |

### Export variables {#op-get-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-export}

`GET /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/export`

The ``.env`` file a release of ``environment`` reads, as
``text/plain``: ``development`` when left out, ``preview`` or
``production``, and for ``preview`` a ``branch`` whose own values win.
Env groups and bindings are included, and build and runtime values
together unless ``target`` narrows them. A value marked secret is never written: a
comment at the top names its key, as it does a value that could not be
read. Only the account, an Admin or Technical member of its team or an
API key with a write permission may export (for an organization, its
owners and admins); anyone else answers 403. Each export is
rate-limited per caller and audited, without values, before it is
answered.

#### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |  |
| `org_slug` | path | string | yes |  |
| `environment` | query | string | no | The environment whose file it is: development, preview or production Default: `development`. |
| `branch` | query | string or null | no | With environment=preview, a branch whose own values win |
| `target` | query | string | no | build, runtime or both: what a build reads, what the instances read, or both Default: `both`. |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |

### Import a .env file into one environment (and branch) {#op-post-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-import}

`POST /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/import`

Import a ``.env`` file into one environment (and branch). Every
value is ``secret`` and reaches ``target`` as the body says. A line
that is not ``KEY=value``, a key the platform sets, or a key given
twice is refused with 422 and its line number, and nothing is saved.

#### Parameters

| Name | In | Type | Required |
| --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |
| `org_slug` | path | string | yes |

#### Request body

`application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `environment` | string | no |  |
| `branch` | string or null | no |  |
| `content` | string | yes |  |
| `secret` | boolean | no | Whether the imported values are secret |
| `target` | string | no |  |
| `replace` | boolean | no | Delete every variable of this environment and branch the file does not set |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |

### Resolved variables {#op-get-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-resolved}

`GET /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/resolved`

Each key a release of ``environment`` (and ``branch``) would read for
``target``, and where its value comes from: ``branch``,
``environment``, ``all``, ``group``, or ``binding`` with the binding's
``id``, ``kind`` and ``label``. Never a value.

#### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |  |
| `org_slug` | path | string | yes |  |
| `environment` | query | string | no | The release's environment: production, preview or development; all for only the values every environment shares Default: `production`. |
| `branch` | query | string or null | no | With environment=preview, a branch whose own values win |
| `target` | query | string | no | build, runtime or both: what a build reads, what the instances read, or both Default: `both`. |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |

### Set a variable {#op-put-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-key}

`PUT /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/{key}`

Set one variable in one environment, creating it when it is new. A
new variable needs a ``value`` and is secret unless ``secret`` is false.
A key the platform sets itself, such as ``PORT`` or one starting
``CORITAN_``, is refused with 422.

#### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |  |
| `key` | path | string | yes |  |
| `org_slug` | path | string | yes |  |
| `environment` | query | string | no | The environment it is set in: all, production, preview or development Default: `all`. |
| `branch` | query | string or null | no | With environment=preview, the one branch the value is for |

#### Request body

`application/json` (required)

| Field | Type | Required |
| --- | --- | --- |
| `value` | string or null | no |
| `secret` | boolean or null | no |
| `target` | string or null | no |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |

### Delete one variable of one environment {#op-delete-api-v1-orgs-org-slug-deployments-deployment-uuid-variables-key}

`DELETE /api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/{key}`

Delete one variable of one environment. Running instances keep it
until the next release; a key the environment does not have answers 404.

#### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `deployment_uuid` | path | string (uuid) | yes |  |
| `key` | path | string | yes |  |
| `org_slug` | path | string | yes |  |
| `environment` | query | string | no | The environment it is deleted from: all, production, preview or development Default: `all`. |
| `branch` | query | string or null | no | With environment=preview, the branch whose value is deleted |

#### Responses

| Status | Meaning |
| --- | --- |
| `200` | Success. |
| `422` | The request is not valid. `detail` lists each problem. |
