# Get the statistics of a kind of record

`GET /api/v1/vaults/{vault}/record-kinds/{recordKind}/statistics` and `QUERY /api/v1/vaults/{vault}/record-kinds/{recordKind}/statistics`

Count the records of one kind in a vault by template and version.

The figures cover every record of the kind in the vault, counted when you ask. Archived records are counted in archived and nowhere else.

This endpoint answers GET and QUERY alike, and both return the same answer. GET sends the parameters in the address, QUERY in the request body. [How QUERY works](https://my.monicahq.com/docs/api/query-method).

## Path parameters

- `vault` (uuid, required): The id of the vault.
- `recordKind` (string, required): contacts for people, or the id of an entity type, as GET /entity-types gives it.

## Returns

The statistics. A vault or an entity type of another account answers 404.

- `data` (object): The statistics.
- `data.type` (string): Always record_statistics.
- `data.attributes` (object): The figures.
- `data.attributes.kind` (object): The kind of record counted.
- `data.attributes.kind.id` (string): contacts, or the id of the entity type.
- `data.attributes.kind.singular` (string): What one record of the kind is called.
- `data.attributes.kind.plural` (string): What several are called.
- `data.attributes.overview` (object): The totals.
- `data.attributes.overview.records` (integer): How many records are not archived.
- `data.attributes.overview.templates_in_use` (integer): How many templates at least one of them follows.
- `data.attributes.overview.on_older_versions` (integer): How many follow a version other than the one their template publishes now.
- `data.attributes.overview.archived` (integer): How many are archived. No other figure counts them.
- `data.attributes.overview.partial` (integer): For people, how many partial contacts the total holds. Null for an entity type.
- `data.attributes.templates` (array): Every template of the kind that is offered or still followed, in the account’s order.
- `data.attributes.templates[]` (object): One template.
- `data.attributes.templates[].id` (uuid): The id of the template.
- `data.attributes.templates[].name` (string): What it is called.
- `data.attributes.templates[].is_default` (boolean): Whether new records of the kind start from it in this vault.
- `data.attributes.templates[].is_active` (boolean): Whether it is turned on. A turned off template appears only while records still follow it.
- `data.attributes.templates[].records` (integer): How many records follow it.
- `data.attributes.templates[].share` (integer): Their share of the total, as a rounded percentage.
- `data.attributes.templates[].published_version` (integer): The number of the version it publishes now. Null when it publishes none.
- `data.attributes.templates[].versions` (array): The versions its records are on, newest first.
- `data.attributes.templates[].versions[]` (object): One version.
- `data.attributes.templates[].versions[].number` (integer): Its number.
- `data.attributes.templates[].versions[].records` (integer): How many records are on it.
- `data.attributes.templates[].versions[].is_published` (boolean): Whether it is the version the template publishes now.
- `data.links` (object): Where the statistics live.
- `data.links.self` (string): Their URL.

## 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/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics \
  -H "Authorization: Bearer $MONICA_TOKEN"
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/vaults/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics', {
  headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->get('https://my.monicahq.com/api/v1/vaults/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics');
```

## Request with QUERY

```sh
curl https://my.monicahq.com/api/v1/vaults/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics \
  -X QUERY \
  -H "Authorization: Bearer $MONICA_TOKEN"
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/vaults/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics', {
  method: 'QUERY',
  headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->query('https://my.monicahq.com/api/v1/vaults/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics');
```

## Response

`200`

```json
{
    "data": {
        "type": "record_statistics",
        "attributes": {
            "kind": {
                "id": "5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b",
                "singular": "Animal",
                "plural": "Animals"
            },
            "overview": {
                "records": 18,
                "templates_in_use": 2,
                "on_older_versions": 3,
                "archived": 2,
                "partial": null
            },
            "templates": [
                {
                    "id": "8b3c2d1e-4f5a-4b6c-9d7e-0f1a2b3c4d5e",
                    "name": "Pet",
                    "is_default": true,
                    "is_active": true,
                    "records": 14,
                    "share": 78,
                    "published_version": 3,
                    "versions": [
                        {
                            "number": 3,
                            "records": 11,
                            "is_published": true
                        },
                        {
                            "number": 2,
                            "records": 3,
                            "is_published": false
                        }
                    ]
                }
            ]
        },
        "links": {
            "self": "https://my.monicahq.com/api/v1/vaults/9f1c2b7a-4e3d-4a6b-8c5d-2e7f1a9b3c4d/record-kinds/5b8e2f1a-7c3d-4e9a-b6f0-1d2c3e4f5a6b/statistics"
        }
    }
}
```
