# Update a variable

> Change a variable's name, description, value or value type, or turn it into a secret (for good). Only the fields sent change. A secret's value is never read back: to change its type, send its value too.

Source: https://docs.stacksync.com/api-reference/variables/update_variable

`PATCH https://api.stacksync.com/v1/workspaces/{workspace_id}/variables/{workflows_variable_id}`

- Operation: `update_variable`
- Resource: Variables
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace. List the ones your key can reach with GET /v1/workspaces. |
| `workflows_variable_id` | string (uuid) | Yes | The variable. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Region of the resource: besg (Europe) or usnv (United States), as GET /v1/regions lists them |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `variable_name` | string \| null, 1 to 255 characters | No |  |
| `description` | string \| null | No |  |
| `value` | string \| null | No | For a secret, send the value with its value_type |
| `value_type` | string (string \| number \| boolean \| object \| array \| json) \| null | No |  |
| `is_secret` | boolean \| null | No | true turns the variable into a secret, for good |
| `validate_only` | boolean, default false | No | Run every check of the write and answer 204 without writing: a refused write answers the error the write would |

## Returns

### 200 OK

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `variable_id` | string | Yes |  |
| `variable_name` | string | Yes |  |
| `variable_resource_id` | string | Yes |  |
| `description` | string \| null | Yes |  |
| `is_secret` | boolean | Yes | A secret's value is encrypted and never answered |
| `value` | string \| null | Yes | The value as text (JSON text for object, array and json); null for a secret |
| `value_type` | string (string \| number \| boolean \| object \| array \| json) \| null | Yes | How workflow steps read the value; for a secret, answered by GET /variables/<id> (stored encrypted with its value, not read by the list) |
| `reference` | string | Yes | What a workflow step writes to read the variable |
| `parent_folder_id` | string \| null | Yes |  |
| `created_time` | string (date-time) | Yes |  |
| `last_modified_time` | string (date-time) | Yes |  |
| `region` | string (besg \| usnv) | Yes |  |

### 204 No Content

No body.

## Example request

```bash
curl -X PATCH "https://api.stacksync.com/v1/workspaces/{workspace_id}/variables/{workflows_variable_id}?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "variable_name": "<variable_name>"
}'
```

## Example response (200)

```json
{
  "variable_id": "<variable_id>",
  "variable_name": "<variable_name>",
  "variable_resource_id": "<variable_resource_id>",
  "description": "<description>",
  "is_secret": false,
  "value": "<value>",
  "value_type": "string",
  "reference": "<reference>",
  "parent_folder_id": "<parent_folder_id>",
  "created_time": "2027-01-15T09:00:00Z",
  "last_modified_time": "2027-01-15T09:00:00Z",
  "region": "besg"
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 404 | Not Found | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "error": string, "msg": string, "field": string \| null }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List variables](https://docs.stacksync.com/api-reference/variables/list_variables)
- [Get a variable](https://docs.stacksync.com/api-reference/variables/get_variable)
- [Create a variable](https://docs.stacksync.com/api-reference/variables/create_variable)
- [Delete a variable](https://docs.stacksync.com/api-reference/variables/delete_variable)