# Add a page

`POST /api/v1/templates/{template}/versions/{version}/pages`

Add a tab to a draft.

A page is a tab on the record, and it exists only inside the version that holds it. It cannot be reused, shared or published on its own, which is why it has no life outside the structure it is part of.

The key is settled here from the label and never rebuilt, so a browser link to the tab keeps working through any rename. Two pages of the same version cannot read the same thing.

Only a draft can be laid out. A version that has been published refuses this, and every other write below.

## Parameters

- `template` (uuid, required): The id of the template. A path that is not a uuid answers 404 without a query being run, so neither the slug nor a sequential number reaches anything here.
- `version` (integer, required): The number of the version within its template, counting from 1, which is the number shown in the version history and the number a change note refers to. It is not a row id, so version 1 of one template and version 1 of another are different things reached through different templates.
- `label` (string, required): What the tab says. Up to 255 characters.
- `key` (string, optional): How the page is addressed in a browser link. Derived from the label when absent, and cleaned either way.

## Returns

The page that was added, placed last. A label another page of the version already reads answers 422.

- `data` (object): The page.
- `data.type` (string): Always structure_version_page. 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.key` (string): How the page is addressed in a browser link. It is settled when the page is added and survives every rename.
- `data.attributes.label` (string): What the tab says.
- `data.attributes.position` (integer): Where the tab sits, counting from 1.
- `data.attributes.sections` (array): The blocks placed on this page. Empty here, since these endpoints answer with the page itself rather than with what is on it. Read the version to get the whole structure.

## 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/templates/7b1c4e92-3d58-4f07-9a26-8c5b0e14d3af/versions/4/pages \
  -X POST \
  -H "Authorization: Bearer $MONICA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
      "label": "Medical"
  }'
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/templates/7b1c4e92-3d58-4f07-9a26-8c5b0e14d3af/versions/4/pages', {
  method: 'POST',
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    label: 'Medical',
  }),
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->post('https://my.monicahq.com/api/v1/templates/7b1c4e92-3d58-4f07-9a26-8c5b0e14d3af/versions/4/pages', [
    'label' => 'Medical',
]);
```

## Response

`201`

```json
{
    "data": {
        "type": "structure_version_page",
        "id": "a1f7b3c8-6e42-4d09-8b57-1c9e0f2a4d36",
        "attributes": {
            "key": "medical",
            "label": "Medical",
            "position": 2,
            "sections": []
        }
    }
}
```
