---
search:
  tags:
    - Secrets
    - POST
seo:
  description: >-
    Creates one secret in a project environment. Fails rather than overwrites
    when the key already… Reference for the POST /secrets endpoint in the
    varsafe API.
sidebar:
  label: Create a secret
  badge: POST
title: Create a secret
type: openapi-operation
---
Creates one secret in a project environment. Fails rather than overwrites when the key already exists.

`POST /secrets`

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

- `projectId` (string<uuid>, required)
- `environment` (string, required)
- `key` (string, required)
- `kind` (string)
- `value` (string)
- `source` (string)
- `expectedVersion` (integer)

Request body example:

```json
{
  "projectId": "5a8591dd-4039-49df-9202-96385ba3eff8",
  "environment": "string",
  "key": "string",
  "kind": "literal",
  "value": "string",
  "source": "string",
  "expectedVersion": 0
}
```

**Responses**

- `201` — Success.
- `400` — The request failed validation. \`field\` names the offending input.
- `401` — No credential was presented, or it is invalid or revoked.
- `403` — The credential is valid but lacks the required scope, role or team access.
- `404` — The resource does not exist, or is not visible to this credential.
- `429` — Rate limited. Retry after the interval named in the response.
- `500` — Unexpected server error. The body never carries internal detail.

Response example, 201:

```json
{
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "projectId": "5a8591dd-4039-49df-9202-96385ba3eff8",
  "environment": "string",
  "key": "string",
  "version": 1,
  "createdAt": "2019-08-24T14:15:22Z",
  "updatedAt": "2019-08-24T14:15:22Z"
}
```
