# Environment Variables

> Source: https://developers.cloud66.com/v3/endpoints/environment-variables/

## Get Environment Variable

URL: https://developers.cloud66.com/v3/endpoints/environment-variables/#get
Endpoint: GET /stacks/:stack_id/environments/:env_var_id
OAuth scope: admin

Get information about a single environment variable.

**Related models:** Environment Variable

### Parameters

- `stack_id` (string, required) — The stack UID
- `env_var_id` (integer, required) — The environment variable ID

### Response

```json
{
  "response": {
    "id": 4153,
    "key": "STACK_PATH",
    "value": "/var/deploy/test-elastic-1/web_head/current",
    "readonly": true,
    "created_at": "2014-08-29T17:21:25Z",
    "updated_at": "2014-08-29T17:21:25Z",
    "is_password": false,
    "is_generated": true,
    "history": [
      {
        "key": 2,
        "value": "/var/deploy/test-elastic-1/web_head/somethingold",
        "created_at": "2015-05-08T14:01:50Z",
        "updated_at": "2015-05-08T14:01:50Z"
      }
    ]
  }
}
```

---

## List Environment Variables

URL: https://developers.cloud66.com/v3/endpoints/environment-variables/#list
Endpoint: GET /stacks/:stack_id/environments
OAuth scope: admin

Get list of all the environment variables of a stack.

**Related models:** Environment Variable, Pagination

### Parameters

- `stack_id` (string, required) — The stack UID

### Response

```json
{
  "response": [
    {
      "id": 4152,
      "key": "STACK_GIT_BRANCH",
      "value": "master",
      "readonly": true,
      "created_at": "2014-08-29T17:21:25Z",
      "updated_at": "2014-08-29T17:21:25Z",
      "is_password": false,
      "is_generated": true,
      "history": [
        {
          "key": 1,
          "value": "develop",
          "created_at": "2015-05-08T15:09:50Z",
          "updated_at": "2015-05-08T15:09:50Z"
        }
      ]
    }
  ],
  "count": 30,
  "pagination": {
    "previous": null,
    "next": null,
    "current": 1,
    "per_page": 30,
    "count": 4,
    "pages": 1
  }
}
```

---

## Add Environment Variable

URL: https://developers.cloud66.com/v3/endpoints/environment-variables/#create
Endpoint: POST /stacks/:stack_id/environments
OAuth scope: admin

Add an environment variable to a stack.

**Related models:** Environment Variable

### Parameters

- `stack_id` (string, required) — The stack UID
- `key` (string, required) — The environment variable key/name
- `value` (string, required) — The environment variable value

### Response

```json
{
  "response": {
    "id": 4169,
    "key": "MY_ENVIRONMENT_VALUE",
    "value": "SOME_VALUE",
    "readonly": false,
    "created_at": "2015-01-01T12:00:00Z",
    "updated_at": "2015-01-01T12:00:00Z",
    "is_password": false,
    "is_generated": false,
    "history": []
  }
}
```

---

## Update Environment Variable

URL: https://developers.cloud66.com/v3/endpoints/environment-variables/#update
Endpoint: PUT /stacks/:stack_id/environments/:env_var_key
OAuth scope: admin

Update an environment variable value.

**Related models:** Environment Variable

### Parameters

- `stack_id` (string, required) — The stack UID
- `env_var_key` (string, required) — The environment variable key/name
- `value` (string, required) — The new environment variable value

### Response

```json
{
  "response": {
    "id": 4153,
    "key": "POSTGRESQL_SLAVE_ADDRESSES",
    "value": "127.0.0.1",
    "readonly": false,
    "created_at": "2014-08-29T17:21:25Z",
    "updated_at": "2015-01-01T12:00:00Z",
    "is_password": false,
    "is_generated": true,
    "history": []
  }
}
```

---

## Delete Environment Variable

URL: https://developers.cloud66.com/v3/endpoints/environment-variables/#delete
Endpoint: DELETE /stacks/:stack_id/environments/:env_var_key
OAuth scope: admin

Delete an environment variable from a stack.

**Related models:** Environment Variable

### Parameters

- `stack_id` (string, required) — The stack UID
- `env_var_key` (string, required) — The environment variable key/name

### Response

```json
{
  "response": {
    "ok": true,
    "message": "Environment variable deleted"
  }
}
```
