---
title: "Create a variable"
method: POST
path: "/v1/workspaces/{workspace_id}/variables"
tags: ["Variables"]
---

# Create a variable

`POST /v1/workspaces/{workspace_id}/variables`

## Request

- Base URL: `https://api.stacksync.com`
- URL: `https://api.stacksync.com/v1/workspaces/{workspace_id}/variables`
- Auth: HTTP bearer

A workspace variable, or a secret (is_secret: its value is encrypted and never answered again). Send an Idempotency-Key to retry safely.

## Path parameters

- `workspace_id` integer, required

## Query parameters

- `region` 'besg' | 'usnv', required

## Headers

- `Idempotency-Key` string, nullable: Makes the create retry-safe for 24 hours: a retry with the same key answers the resource the first call created, with the Idempotent-Replayed: true header, and creates nothing. 1 to 255 visible ASCII characters. The same key with a different request answers 422; while the first call still runs, 409.

## Request body

- CreateVariableBody
  - `variable_name` string, required
  - `value` string: The value as text; for object, array and json the JSON text
  - `value_type` 'string' | 'number' | 'boolean' | 'object' | 'array' | 'json'
  - `is_secret` boolean: A secret's value is encrypted and never answered; cannot be undone
  - `description` string, nullable
  - `variable_resource_id` string, nullable: The id workflow steps read the variable by; generated from the name when absent
  - `parent_folder_id` string, nullable: The folder to create the variable in, the root when absent
  - `validate_only` boolean: Run every check of the write and answer 204 without writing: a refused write answers the error the write would

## Response `201`

Created

- CreatedVariable
  - `variable_id` string, required
  - `variable_name` string, required
  - `variable_resource_id` string, required
  - `description` string, nullable, required
  - `is_secret` boolean, required: A secret's value is encrypted and never answered
  - `value` string, nullable, required: The value as text (JSON text for object, array and json); null for a secret
  - `value_type` 'string' | 'number' | 'boolean' | 'object' | 'array' | 'json', required
  - `reference` string, required: What a workflow step writes to read the variable
  - `parent_folder_id` string, nullable, required
  - `created_time` string, date-time, required
  - `last_modified_time` string, date-time, required
  - `region` 'besg' | 'usnv', required

## Other responses

- `204`: No Content
- `400`: Bad Request
- `403`: Forbidden
- `409`: Conflict
- `422`: Unprocessable Content

---

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