# Secrets Store API

> Every endpoint of Secrets Store on your realm's host, by area, with what each does and the page that covers it.

Every endpoint Secrets Store serves on your realm's host. Each is called by a user signed in to the realm, as
themselves, with their session as a cookie; [Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`, and the
paging, revision and error rules every call shares. For example:

```sh
curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/data/web/github \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

Who may call each endpoint is on its page: most are for any user signed in to the realm, acting on their own vaults
and what is granted to them; `enable`, `grantees` and the realm's secrets key are for realm administrators.

In the tables, `<vault>` is the vault a call is made to: `me`, `user/<user>`, `group/<group>` or `realm` (see
[Vaults](/secrets-store/vaults/)). `<path>` is a secret's path, such as `web/github`. Every answer carries its content
under `data`; a call that changes something and has nothing to report answers `204`. Until a realm administrator
turns the store on, every call but `enable` answers `409`. `PUT` is taken wherever `POST` is.

## Turning the store on

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/enable` | Turns the store on for the realm, writing its settings at their defaults: `201` the first time, `200` after. A realm administrator only | [Realm settings](/secrets-store/realm-settings/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/config` | The defaults every vault takes: `max_versions`, `cas_required`, `delete_version_after`. Anyone signed in | [Realm settings](/secrets-store/realm-settings/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/vaultSettings/vaultSettings` | The realm's secrets settings, with their `rev` | [Realm settings](/secrets-store/realm-settings/) |
| `PATCH` | `https://foobar.cvyuh.com/api/v0/am/objects/v1/vaultSettings/vaultSettings` | Changes the settings named, each in its section; `If-Match` guards it | [Realm settings](/secrets-store/realm-settings/) |

## Secrets

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/data/<path>` | The latest version's values and metadata; `?version=N` for another | [Versions](/secrets-store/secrets/versions/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/data/<path>` | Writes a new version: `{ "options": { "cas": N }, "data": { … } }` | [Versions](/secrets-store/secrets/versions/) |
| `PATCH` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/data/<path>` | Merges `data` into the latest, as a new version | [Versions](/secrets-store/secrets/versions/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/data/<path>` | Deletes the latest version, softly | [Delete, undelete and destroy](/secrets-store/secrets/delete-and-destroy/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/delete/<path>` | Deletes the versions named, softly: `{ "versions": [N, …] }` | [Delete, undelete and destroy](/secrets-store/secrets/delete-and-destroy/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/undelete/<path>` | Brings deleted versions back | [Delete, undelete and destroy](/secrets-store/secrets/delete-and-destroy/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/destroy/<path>` | Removes the versions' values for good | [Delete, undelete and destroy](/secrets-store/secrets/delete-and-destroy/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/metadata/<path>` | The version map, settings and labels | [Metadata](/secrets-store/secrets/metadata/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/metadata/<path>` | Sets settings and replaces every label | [Metadata](/secrets-store/secrets/metadata/) |
| `PATCH` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/metadata/<path>` | Sets settings and merges labels | [Metadata](/secrets-store/secrets/metadata/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/metadata/<path>` | Deletes the whole secret: every version, its settings and labels | [Delete, undelete and destroy](/secrets-store/secrets/delete-and-destroy/) |
| `GET` or `LIST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/metadata/<prefix>?list=true` | The next segment of each path under the prefix; folders end in `/` | [Listing](/secrets-store/secrets/listing/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/subkeys/<path>` | The names inside a version, values left out; `?version=N`, `?depth=D` | [Subkeys](/secrets-store/secrets/subkeys/) |

## Sharing

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/grants/<path>` | The secret's grants, each with `edgeId`, `access`, `validTo`, `grantedBy` and `live` | [Grants](/secrets-store/sharing/grants/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/grants/<path>` | Gives a grant: `{ "user" or "group": id, "access": "view" or "use", "validTo": time }` | [Grants](/secrets-store/sharing/grants/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/grants/<path>/<edgeId>` | Takes one grant back | [Grants](/secrets-store/sharing/grants/) |
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/shared` | Every secret granted to the caller or their groups: `vault`, `path`, `access` | [Grants](/secrets-store/sharing/grants/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/grantees/<user>` | Takes back every grant to a user, in every vault, unlisted: `{ "removed": N }`. A realm administrator only | [Offboard someone](/secrets-store/guides/offboard-someone/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/<vault>/share/<path>` | Makes a one-time share: `{ "version": N, "ttl": s, "recipient": id }`; answers `link` and `expires_at` | [One-time shares](/secrets-store/sharing/one-time-shares/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/shares` | Reads a one-time share once: `{ "link": … }` | [One-time shares](/secrets-store/sharing/one-time-shares/) |

## Emergency access

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `GET` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency` | The caller's nominations (`nominated`) and those naming them (`nominatedFor`) | [Emergency access](/secrets-store/emergency-access/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency` | Nominates a user: `{ "nominee": id, "delay": s }` | [Emergency access](/secrets-store/emergency-access/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency/<id>/request` | The nominee asks; the delay starts | [Emergency access](/secrets-store/emergency-access/) |
| `POST` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency/<id>/refuse` | The grantor refuses the request standing | [Emergency access](/secrets-store/emergency-access/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency/<id>` | Either side ends the nomination | [Emergency access](/secrets-store/emergency-access/) |

## Keys and protection

| Method | Endpoint | What it does | Page |
|---|---|---|---|
| `PUT` | `https://foobar.cvyuh.com/api/v0/am/keys/v1/secrets/encryption` | Adds a new version of the realm's secrets key. A realm administrator only | [Key rotation](/secrets-store/keys-and-protection/key-rotation/) |
| `DELETE` | `https://foobar.cvyuh.com/api/v0/am/keys/v1/secrets/encryption?shred=true` | Destroys every version of the realm's secrets key, and with it the realm's vault | [Crypto-shredding](/secrets-store/keys-and-protection/crypto-shredding/) |

## Sealed vaults

Sealed vaults' endpoints are planned for customers: no client seals on a user's device yet, so none of them can be
used. Every planned endpoint is in
[What's next for sealed vaults](/secrets-store/sealed-vaults/whats-next/#planned-api).

## Errors

Every error answers with its status and a body naming the error and why. The ones this API gives:

| Status | When | What to do |
|---|---|---|
| `400` | The body isn't a JSON object, or lacks a field the call needs (`data`, `versions`, `link`, `nominee`) | Send the body the call's page shows |
| `400` | A path is empty or has an empty, `.` or `..` segment | Use a path such as `web/github` |
| `400` | Check-and-set: `options.cas` doesn't match the latest version, or is required and missing | Read the latest version and write again with it. See [Check-and-set](/secrets-store/secrets/check-and-set/) |
| `400` | A share's `ttl` is `0` or past the realm's `shareMaxTtl`; the version shared is deleted or destroyed | Send a `ttl` in range; share a live version |
| `400` | A grant names both or neither of `user` and `group`, or its `validTo` is past or not RFC 3339 | Send one grantee and a future time |
| `400` | A nomination names yourself or a delay of `0`; a refusal with no request standing | See [Emergency access](/secrets-store/emergency-access/) |
| `400` | A settings change names a field the settings don't have, or a value out of range | See [Realm settings](/secrets-store/realm-settings/) |
| `401` | No session, or it has ended | Sign in again; see [Call the API](/develop/api/) |
| `403` | Not a realm administrator, for `enable`, `grantees` and the realm's vault | Ask someone holding `RealmOwner` |
| `403` | No right in a group's vault (not a member) or the realm's, or a `use` grant asking for more than the latest version | Ask for membership or a `view` grant |
| `404` | In a personal vault: the path isn't there, or you have no access. The store doesn't say which | Ask the owner for a grant |
| `404` | A user, group, grant, nomination or version isn't there; a one-time share is spent, expired or for someone else | Check the id. A share that answers `404` on its first read was read by someone else: change the secret |
| `404` | A grantee or nominee hasn't used the store yet, or no member has opened a group's vault | They make one call to the store; then retry |
| `404` | The session is for another realm | Sign in to the realm the vault is in |
| `405` | The method isn't one the operation takes | Use the method in the tables above |
| `409` | The store isn't turned on for the realm | A realm administrator calls `enable` |
| `412` | The settings, or a nomination, changed since you read them | Read again and retry with the new `rev` |
| `413` | The request body is larger than 2 MiB | Keep a secret's values and labels under 2 MiB |
| `503` | The realm has no secrets key: the realm's vault and one-time shares can't be used | See [Crypto-shredding](/secrets-store/keys-and-protection/crypto-shredding/) |

## Limits

| Limit | Default | Range |
|---|---|---|
| Request body | 2 MiB | fixed |
| Versions kept per path | 10 | 1 to 100 |
| One-time share lifetime | 600 seconds | 1 second to `shareMaxTtl` (a week by default, at most 30 days) |
| Emergency delay | 604800 seconds | at least 1 second |
| Request rate, secrets per vault, grants per secret | no limit of the store's own | |

Each feature page lists the limits that apply to it.
