# Set a variable

Source: https://openpanel.sh/docs/api/variables/set-a-variable

Sets it on the project, an environment or a service, replacing one of the same name in that scope. The narrowest scope wins at deploy. Takes effect at the next deployment.

`PUT https://openpanel.sh/api/v1/projects/{projectId}/variables/{name}`

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectId` | path | yes |  |
| `name` | path | yes | Letters, digits and underscores, not starting with a digit. |

## Request body

JSON, `VariableSet`.

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | Set a variable | `application/json`, `Variable` |
| 401 | No valid credential was sent. | `application/problem+json`, `Problem` |
| 403 | The credential may not do this. | `application/problem+json`, `Problem` |
| 404 | Not found, or not visible to this credential. | `application/problem+json`, `Problem` |
| 409 | It clashes with something that exists, such as a name in use. | `application/problem+json`, `Problem` |
| 422 | The input was refused; detail says why. | `application/problem+json`, `Problem` |
| 429 | Too many requests; wait for Retry-After seconds. | `application/problem+json`, `Problem` |

## Schemas

### Problem

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "description": "A link to the error's explanation in the docs."
    },
    "title": {
      "type": "string"
    },
    "status": {
      "type": "integer"
    },
    "code": {
      "type": "string",
      "description": "Stable machine-readable code: not_found, forbidden, invalid, conflict, rate_limited, not_implemented, …"
    },
    "detail": {
      "type": "string",
      "description": "What went wrong, in a sentence written for a person."
    }
  },
  "required": [
    "type",
    "title",
    "status",
    "code",
    "detail"
  ]
}
```

### Variable

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "projectId": {
      "type": "string",
      "format": "uuid"
    },
    "environmentId": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ]
    },
    "serviceId": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ]
    },
    "name": {
      "type": "string"
    },
    "secret": {
      "type": "boolean"
    },
    "value": {
      "description": "Null for a secret: its value is never read back.",
      "type": [
        "string",
        "null"
      ]
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "projectId",
    "environmentId",
    "serviceId",
    "name",
    "secret",
    "value",
    "updatedAt"
  ]
}
```

### VariableSet

```json
{
  "type": "object",
  "properties": {
    "value": {
      "type": "string",
      "maxLength": 65536
    },
    "secret": {
      "description": "Sealed and never shown again; only deploys use it.",
      "type": "boolean"
    },
    "environmentId": {
      "description": "Set it for one environment only.",
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ]
    },
    "serviceId": {
      "description": "Set it for one service only.",
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "value"
  ],
  "additionalProperties": false
}
```