# Set the categories of several contacts

`PUT /api/v1/vaults/{vault}/contacts/categories`

Give up to 500 contacts of a vault the categories you list for each, in place of the ones they held.

Each contact ends with exactly the categories listed for it, and an empty list removes them all. The categories go into the first category field of the contact's template, as editing the contact would write them, and any other category field is emptied.

A contact whose template has no category field is left as it was and listed with the reason, and so is one whose category is required when you remove it. A category held in a sensitive field counts only for a key reaching sensitive fields. Every change is written to the account log.

## Parameters

- `vault` (string, required): The vault the contact lives in, named either by the readable name it reports as slug or by its id. Both answer.
- `contacts` (array, required): Each contact and the categories it ends with. At most 500.
- `contacts[].contact` (string, required): The id or the address of a contact of this vault.
- `contacts[].categories` (array, required): The ids of the categories the contact ends with, as the list of contact categories gives them. Empty removes every category.

## Returns

Which contacts changed, and which were left as they were with the reason. A vault belonging to somebody else answers 404. More than 500 contacts answers 422 on contacts, a contact that is not in the vault answers 422 on its contact, and a category of somebody else answers 422 on its categories. A contact deleted in the meantime is left as it was, listed with the reason, and the others still change. Nothing is written when the call is refused.

- `data` (object): What the change did.
- `data.type` (string): Always contact_category_change.
- `data.attributes` (object): Who changed and who did not.
- `data.attributes.changed` (array): The contacts now holding the categories listed for them.
- `data.attributes.changed[]` (string): The id of one of them.
- `data.attributes.unchanged` (array): The contacts left as they were.
- `data.attributes.unchanged[]` (object): One of them.
- `data.attributes.unchanged[].contact` (string): The id of the contact.
- `data.attributes.unchanged[].reason` (string): Why it was left as it was, in the language of the account.

## 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/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/categories \
  -X PUT \
  -H "Authorization: Bearer $MONICA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
      "contacts": [
          {
              "contact": "c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364",
              "categories": [
                  12
              ]
          }
      ]
  }'
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/categories', {
  method: 'PUT',
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    contacts: [{"contact":"c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364","categories":[12]}],
  }),
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->put('https://my.monicahq.com/api/v1/vaults/9d4f1c2e-7b3a-4f88-9a2d-6c1e5b0f7a31/contacts/categories', [
    'contacts' => [['contact' => 'c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364', 'categories' => [12]]],
]);
```

## Response

`200`

```json
{
    "data": {
        "type": "contact_category_change",
        "attributes": {
            "changed": [
                "c4a1f7b2-8e36-4d59-b0a7-2f5c9d81e364"
            ],
            "unchanged": [
                {
                    "contact": "6f3c1d2e-8a4b-4c5d-9e6f-7a8b9c0d1e2f",
                    "reason": "Their template has no category field."
                }
            ]
        }
    }
}
```
