---
title: "Add or update an environment variable"
method: PUT
path: "/context/{context_id}/environment-variable/{env_var_name}"
tags: ["Context"]
---

# Add or update an environment variable

`PUT /context/{context_id}/environment-variable/{env_var_name}`

## Request

- Base URL: `https://circleci.com/api/v2`
- URL: `https://circleci.com/api/v2/context/{context_id}/environment-variable/{env_var_name}`
- Auth: one of:
  - API key in header `Circle-Token`
  - HTTP bearer
  - HTTP basic
  - API key in query parameter `circle-token`

Create or update an environment variable within a context. Returns information about the environment variable, not including its value.

## Path parameters

- `context_id` string, uuid, required
- `env_var_name` string, required

## Request body

- object
  - `value` string, required: The value of the environment variable

## Response `200`

The new environment variable

- union
  - object
    - `variable` string, required: The name of the environment variable
    - `created_at` string, date-time, required: The date and time the environment variable was created.
    - `updated_at` string, date-time, required: The date and time the environment variable was updated
    - `context_id` string, uuid, required: ID of the context (UUID)
  - object: message response
    - `message` string, required: A human-readable message

## Other responses

- `401`: Credentials provided are invalid.
- `404`: Entity not found.
- `429`: API rate limits exceeded.
- `500`: Internal server error.

---

[API](https://skmtc.dev/circleci/apis/circleci-api.md) - [All operations](https://skmtc.dev/circleci/apis/circleci-api/llms.txt) - [OpenAPI document](https://skmtc.dev/circleci/apis/circleci-api/revisions/b9c0e0c24058?raw)
