---
title: "Update a variable"
method: PUT
path: "/api/v4/projects/{id}/variables/{key}"
tags: ["ci_variables"]
---

# Update a variable

`PUT /api/v4/projects/{id}/variables/{key}`

## Request

- Base URL: `https://gitlab.com`
- URL: `https://gitlab.com/api/v4/projects/{id}/variables/{key}`
- Auth: none declared

Updates a project variable. If there are multiple variables with the same key, use `filter` to select the correct `environment_scope`.

## Path parameters

- `id` string, required
- `key` string, required

## Request body

- PutApiV4ProjectsIdVariablesKey: Update a variable
  - `value` string: The value of a variable
  - `protected` boolean: Whether the variable is protected
  - `masked` boolean: Whether the variable is masked
  - `environment_scope` string: The environment_scope of a variable
  - `raw` boolean: Whether the variable will be expanded
  - `variable_type` 'env_var' | 'file': The type of the variable. Default: env_var
  - `filter` object: Available filters: [environment_scope]. Example: filter[environment_scope]=production
    - `environment_scope` string: The environment scope of a variable
  - `description` string: The description of the variable

## Response `200`

Update a variable

- APIEntitiesCiVariable: API_Entities_Ci_Variable model
  - `variable_type` string, required
  - `key` string, required
  - `value` string, required
  - `hidden` boolean
  - `protected` boolean
  - `masked` boolean
  - `raw` boolean
  - `environment_scope` string
  - `description` string

## Other responses

- `404`: Variable Not Found

---

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