# Give an account a role

`POST https://api.mailmasker.org/api/v1/admin/users/:id/roles`

Add a role to an account, and with it everything the role allows.

- Who can use it: Site admins
- Area: Users and roles
- Answers 200 OK when it works
- Page: https://developer.mailmasker.org/admin-grant-role

The account gets every permission the role carries. Giving `site_admin` makes it a full site admin. Giving a role the account already has changes nothing. Each grant is recorded in the audit log.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `id` | path | yes | The account's number, from the account list. | `7` |
| `role` | body | yes | The role's name, as the role list shows it. | `auditor` |

## Good to know

- An unknown account answers 404, and an unknown role 400.

## Examples

cURL:

```bash
curl -s -X POST 'https://api.mailmasker.org/api/v1/admin/users/7/roles' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"role":"auditor"}'
```

Perl:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $ua  = Mojo::UserAgent->new;
my $res = $ua->post('https://api.mailmasker.org/api/v1/admin/users/7/roles',
    { Authorization => "Bearer $ENV{TOKEN}" },
    json => { role => 'auditor' })->result;
die $res->code, ' ', ($res->json('/error') // $res->message), "\n" unless $res->is_success;
print $res->body, "\n";
```

homelab-cli:

```bash
homelab-cli admin users grant-role 7 auditor
```

## Response

200 OK:

```json
{ "ok": true }
```
