# Add somebody to a group

`POST /api/v1/vaults/{vault}/groups/{group}/members`

Put a contact of the vault in a group, optionally with a role and the dates they joined and left.

Somebody who left and came back gets a new membership, so the group keeps both periods. Somebody already in the group today cannot be added twice: that answers 422 on contact, saying they are already in this group.

A left_on before joined_on answers 422 on left_on, saying somebody cannot leave a group before they joined it. A date sent without its precision is taken as known to the day.

Groups are not yet available to every account. Until they are available to yours, every endpoint here answers 404.

## Parameters

- `vault` (string, required): The vault the groups live in, named either by the readable name it reports as slug or by its id.
- `group` (uuid, required): The id of the group. One addressed through the wrong vault, or belonging to another account, answers 404.
- `contact` (string, required): The person to add, a contact of the same vault, named by their slug or their id. A contact of another vault answers 404.
- `role` (string, optional): What the person is in the group, in your own words, up to 255 characters.
- `joined_on` (string, optional): When the person joined, written as a year, a month and a day.
- `joined_precision` (string, optional): How much of joined_on is known: day, month, year, decade or unknown.
- `left_on` (string, optional): When the person left, written as a year, a month and a day. A date before joined_on answers 422.
- `left_precision` (string, optional): How much of left_on is known: day, month, year, decade or unknown.

## Returns

The membership object that was recorded.

- `data` (object): The membership.
- `data.type` (string): Always group_membership. 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.group` (object): The group the membership is in.
- `data.attributes.group.id` (uuid): The id of the group.
- `data.attributes.group.name` (string): What the group is called.
- `data.attributes.contact` (object): The person the membership is about.
- `data.attributes.contact.id` (uuid): The id of the contact.
- `data.attributes.contact.slug` (string): The readable name of the contact, which addresses it as well as its id.
- `data.attributes.contact.name` (string): The name of the contact, as it is shown.
- `data.attributes.role` (string): What the person is in the group, in their own words, or null.
- `data.attributes.joined_on` (string): When the person joined, written as a year, a month and a day, or null.
- `data.attributes.joined_precision` (string): How much of the date is known: day, month, year or decade. Always unknown when there is no date.
- `data.attributes.left_on` (string): When the person left, written as a year, a month and a day, or null while they are still in the group.
- `data.attributes.left_precision` (string): How much of the date is known: day, month, year or decade. Always unknown when there is no date.
- `data.attributes.is_current` (boolean): True while the person is in the group, which is while left_on is null.
- `data.attributes.created_at` (timestamp): When the membership was recorded, as a count of seconds since 1970.
- `data.attributes.updated_at` (timestamp): When it last changed, as a count of seconds since 1970, or null.

## 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://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/members \
  -X POST \
  -H "Authorization: Bearer $MONICA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
      "contact": "angela-martin",
      "role": "Chair",
      "joined_on": "2005-03-01",
      "joined_precision": "month"
  }'
```

```javascript
const response = await fetch('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/members', {
  method: 'POST',
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    contact: 'angela-martin',
    role: 'Chair',
    joined_on: '2005-03-01',
    joined_precision: 'month',
  }),
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->post('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/members', [
    'contact' => 'angela-martin',
    'role' => 'Chair',
    'joined_on' => '2005-03-01',
    'joined_precision' => 'month',
]);
```

## Response

`201`

```json
{
    "data": {
        "type": "group_membership",
        "id": "c81f4e2a-6b97-4d35-a0e8-2f5b913d7c64",
        "attributes": {
            "group": {
                "id": "5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7",
                "name": "Party planning committee"
            },
            "contact": {
                "id": "3b9e1f70-4c2d-4a86-b5e3-7d0a62f8c915",
                "slug": "angela-martin",
                "name": "Angela Martin"
            },
            "role": "Chair",
            "joined_on": "2005-03-01",
            "joined_precision": "month",
            "left_on": null,
            "left_precision": "unknown",
            "is_current": true,
            "created_at": 1791547200,
            "updated_at": 1791547200
        }
    }
}
```
