> ## Documentation Index
> Fetch the complete documentation index at: https://cobalt-55-abhishek.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Variable Value

> Set a scoped value for an environment-variable definition.

Upsert a scoped value for a variable definition. The value is validated against the definition's `var_format` and encrypted if the definition is marked encrypted. The scope is determined by what you pass: nothing for org scope, `linked_account_id` for linked-account scope, `workflow_id` for workflow scope.

## Authentication

<ParamField header="x-api-key" type="string" required>Your Refold API key.</ParamField>
<ParamField header="linked_account_id" type="string">Required (header or body) when setting a linked-account-scoped value.</ParamField>

<Note>
  For linked-account-scoped values you may instead authenticate with a session token (`Authorization: Bearer ...`); it is restricted to that account's scope.
</Note>

## Body Parameters

<ParamField body="variable_definition_id" type="string" required>The definition to set a value for.</ParamField>
<ParamField body="value" type="string" required>The value. Validated against the definition's `var_format`.</ParamField>
<ParamField body="linked_account_id" type="string">Set the linked-account-scoped value for this account.</ParamField>
<ParamField body="workflow_id" type="string">Set the workflow-scoped value for this workflow.</ParamField>

## Response

<Tabs>
  <Tab title="200 OK">
    Returns the stored value document. The `value` is encrypted at rest if the definition is encrypted.
    <ResponseField name="_id" type="string">Value document ID (used to delete it).</ResponseField>
    <ResponseField name="variable_definition_id" type="string">The definition.</ResponseField>
    <ResponseField name="linked_account_id" type="string">Account scope, if any.</ResponseField>
    <ResponseField name="value" type="string">Stored value (ciphertext if encrypted).</ResponseField>
  </Tab>

  <Tab title="400 Bad Request">
    Returned on format-validation failure or missing required scope auth.
    <ResponseField name="status_code" type="integer">HTTP status code.</ResponseField>
    <ResponseField name="http_error_type" type="string">Error category.</ResponseField>
    <ResponseField name="error" type="string">Internal error code.</ResponseField>
    <ResponseField name="message" type="string">Human-readable error description.</ResponseField>
  </Tab>
</Tabs>

<ResponseExample>
  ```json 200 theme={null}
  {
    "_id": "6a314b06d396207fd24fb16b",
    "variable_definition_id": "6a1401de41e63efd08fb3e54",
    "org_id": "6500a1b2c3d4e5f6a7b8c9d0",
    "environment": "test",
    "linked_account_id": "user_12345",
    "value": "MGNmZDM1NjJhM2U0ZmQzODU5OGU3N2NhNGJiYWNhMGU=",
    "createdAt": "2026-06-16T13:09:26.023Z"
  }
  ```

  ```json 400 theme={null}
  {
    "status_code": 400,
    "http_error_type": "BAD_REQUEST",
    "error": "SERVER_ERROR",
    "message": "value does not match the variable format"
  }
  ```
</ResponseExample>

<RequestExample>
  ```bash cURL (linked-account scope) theme={null}
  curl -X POST "https://app.refold.ai/api/v2/public/env/values" \
    -H "x-api-key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "variable_definition_id": "YOUR_DEFINITION_ID",
      "value": "your-value",
      "linked_account_id": "YOUR_LINKED_ACCOUNT_ID"
    }'
  ```

  ```bash cURL (org scope) theme={null}
  curl -X POST "https://app.refold.ai/api/v2/public/env/values" \
    -H "x-api-key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "variable_definition_id": "YOUR_DEFINITION_ID", "value": "your-value" }'
  ```
</RequestExample>
