---
search:
  tags:
    - Component variables
    - POST
seo:
  description: >-
    Sets a variable on the component,… Reference for the POST
    /project/{project_id}/environment/{environment_id}/component/variable
    endpoint in the Platform API.
sidebar:
  label: Create a component variable
  badge: POST
title: Create a component variable
type: openapi-operation
---
Sets a variable on the component, as a key-value pair or a file.

`POST /project/{project_id}/environment/{environment_id}/component/variable`

**Request body** (`application/json`, required)

- `component_kind` (component_kind, required) — Component kind for component-scoped variables
- `component_id` (uuid, required) — A universally unique identifier (UUID) string
- `key` (string, required) — Variable key identifier.
- `var_type` (variable_type, required) — Variable value type
- `value` (string, required) — Variable value.
- `file_path` (string) — Required when var\_type is file. Must be an absolute path.

Request body example:

```json
{
  "component_kind": "Kjob",
  "component_id": "41afafe5-2a48-424a-baef-34c2ad44ef7b",
  "key": "string",
  "var_type": "key_value",
  "value": "string",
  "file_path": "string"
}
```

**Responses**

- `200` — Variable created successfully
- `default` — Error

Response example, 200:

```json
{
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6",
  "project_id": "405d8375-3514-403b-8c43-83ae74cfe0e9",
  "environment_id": "40ef0e48-a11f-4963-a229-e396c9f7e7c4",
  "visibility": "project",
  "var_type": "key_value",
  "key": "string",
  "is_secret": true,
  "managed": true,
  "value": "string",
  "file_path": "string",
  "component_kind": "Kjob",
  "component_id": "41afafe5-2a48-424a-baef-34c2ad44ef7b",
  "created_at": "2019-08-24T14:15:22Z",
  "updated_at": "2019-08-24T14:15:22Z"
}
```
