# Create a vault

`POST /api/v1/vaults`

Open a compartment. It starts empty, and it goes at the end of your list.

If your account held no vault, this one becomes the vault records land in when nothing says which. Exactly one vault is that at any time, and there was nothing else to be it.

## Body parameters

- `name` (string, required): What the vault is called. Up to 255 characters. Markup and surrounding blank space are stripped.
- `description` (string, optional): What the vault is for. Up to 65535 characters. Absent, empty or null all mean it has none.
- `colour` (string, optional, defaults to #3f5fd0): Exactly one of #3f5fd0, #4f8a49, #9a6a24, #9a3f2b, #6b4fa8, #2f7f86, #a8447a or #4a4a52, written in lower case. Absent means #3f5fd0.
- `is_default` (boolean, optional): True makes this the vault records land in when nothing says which, and takes that over from whichever vault held it. False, or saying nothing, changes nothing: exactly one of your vaults is it while you have a vault at all, so there would be nothing to hand it to.
- `structure_version_id` (integer, optional): The published version of one of your active contact templates. Every new contact in this vault starts from it, beginning with the contact standing for you, which is created with the vault. Left out, the vault starts from Basic contact, or from the next template Monica supplied when Basic contact is gone. A draft, a version belonging to somebody else, and a version describing something other than a contact are each refused.

## Returns

The new vault object. Keep its id: every other call here names the vault by it.

- `data` (object): The vault.
- `data.type` (string): Always vault. It names the kind of record, so a caller holding several kinds can tell them apart without looking at where they came from.
- `data.id` (string): The id of this record, as a string even when it reads as a number. It is what every endpoint naming this record takes.
- `data.attributes` (object): Everything the record holds.
- `data.attributes.slug` (string): The readable name the vault is addressed by, built from its name and unique within your account. It is not stable: renaming the vault rebuilds it and the previous one stops answering, which is why a stored reference should be the id. Nothing lets you choose or edit it.
- `data.attributes.name` (string): What the vault is called. Up to 255 characters. Reduced to plain text when it was written down, so no markup survives here.
- `data.attributes.description` (string): What the vault is for, up to 65535 characters, or null when nobody said. Null is the ordinary state of a vault nobody described, not a sign of anything missing.
- `data.attributes.colour` (string): Exactly one of #3f5fd0, #4f8a49, #9a6a24, #9a3f2b, #6b4fa8, #2f7f86, #a8447a or #4a4a52, written in lower case. It is how vaults are told apart at a glance, and it is decoration: nothing depends on it.
- `data.attributes.position` (integer): Where the vault sits in your list, counting from 1. It is the order you arranged, and it is the order the list endpoint answers in.
- `data.attributes.is_default` (boolean): Whether records land here when nothing says which vault. Exactly one of your vaults is true while you hold a vault at all, and none is while you hold none.
- `data.attributes.contact_count` (integer): How many contacts the vault holds, counting the archived and the partial ones. It is a running count kept as contacts are written down and deleted, rather than something counted when you ask.
- `data.attributes.created_at` (timestamp): When the vault was opened, as a count of seconds since 1970 rather than a written date.
- `data.attributes.updated_at` (timestamp): When its wording last changed, as a count of seconds. Equal to created_at until it first changes.
- `data.links` (object): Where to find this record.
- `data.links.self` (string): The absolute address this record is read from.
- `data.links.web` (string): The page of the vault in the application, which opens for somebody signed in rather than for a key. It is the link to give a person.

## Rate limit

Sixty requests per minute, per user, shared by every key and device. Every answer carries the budget left in `X-RateLimit-Remaining`.

## Request

```sh
curl https://my.monicahq.com/api/v1/vaults \
  -X POST \
  -H "Authorization: Bearer $MONICA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
      "name": "Dunder Mifflin",
      "description": "Everybody at the Scranton branch.",
      "colour": "#4f8a49"
  }'
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/vaults', {
  method: 'POST',
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    name: 'Dunder Mifflin',
    description: 'Everybody at the Scranton branch.',
    colour: '#4f8a49',
  }),
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->post('https://my.monicahq.com/api/v1/vaults', [
    'name' => 'Dunder Mifflin',
    'description' => 'Everybody at the Scranton branch.',
    'colour' => '#4f8a49',
]);
```

## Response

`201`

```json
{
    "data": {
        "type": "vault",
        "id": "9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31",
        "attributes": {
            "slug": "dunder-mifflin",
            "name": "Dunder Mifflin",
            "description": "Everybody at the Scranton branch.",
            "colour": "#4f8a49",
            "position": 1,
            "is_default": true,
            "contact_count": 12,
            "created_at": 1756252800,
            "updated_at": 1756339200
        },
        "links": {
            "self": "https://my.monicahq.com/api/v1/vaults/dunder-mifflin",
            "web": "https://my.monicahq.com/vaults/dunder-mifflin"
        }
    }
}
```
