# Store a secret

> Keep a password or an API key in your own vault, read it back, and read any earlier version of it.

You have a password you'd rather not keep in a text file. Stored in your own vault, it is sealed under your own key,
so no one else acting as themselves can read it, a realm administrator included, and every change you make is kept as
a version you can go back to. [Known limitations](/reference/known-limitations/#secrets-store) lists the exceptions,
such as someone who can sign in as you.

**Before you start:** a realm administrator has turned the store on, and you are signed in to the realm with your
session in `$CVYUH_SESSION` ([Call the API](/develop/api/) shows how).

## Store it and read it back

<Steps>

1. Write the secret under a path you choose, such as `web/github`:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/data/web/github \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "data": { "user": "maya", "password": "<password>" } }'
   ```

   The realm answers `200` with the new version's metadata. This is version 1. A `409` means the store isn't on yet;
   ask a realm administrator to turn it on.

2. Read it back:

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

   The answer carries the values under `data.data` and the version's metadata under `data.metadata`.

3. Change one value. A `PATCH` merges what you send into the latest version, as a new version:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/data/web/github \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "data": { "password": "<new password>" } }'
   ```

   A value sent as `null` is removed.

</Steps>

## Check it worked

Read the first version again:

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

It still holds the original password: a path keeps its last 10 versions unless you or the realm set another limit.

## Undo it

Delete the latest version with a `DELETE` on `https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/data/web/github`, or
the whole secret with a `DELETE` on `…/me/metadata/web/github`. See [Take back a change](/secrets-store/guides/take-back-a-change/).

## Related

- [Versions](/secrets-store/secrets/versions/): how each write becomes a version.
- [Vaults](/secrets-store/vaults/): your vault, a group's and the realm's.
- [Change a secret safely](/secrets-store/guides/change-a-secret-safely/): when someone else writes it too.
