## Create a role (identity:admin)

`POST /api/hr/v1/roles`

Module: HR · operationId: `createRole` · Tag: Access · Auth: access token (`Authorization: Bearer <accessToken>`)

### Request body

`application/json` (required)

- `name` (string, required): Name of the role
- `description` (string): Description of the role
- `id` (string): Id of the role
- `key` (string, read-only): Stable key of the role
- `locked` (boolean, read-only): Built-in role whose permissions cannot be changed
- `memberCount` (integer, read-only): Number of employees holding the role
- `permissions` (array of string): Permissions of the role
- `systemKey` (string, read-only): Key of a built-in role, empty for roles of the tenant
- `version` (integer): Version for optimistic locking: send the version you read with a change (stale: 409 version_conflict)

Example:

```json
{
  "description": "Tickets bearbeiten, Wissen lesen, eigene Zeiten und Abwesenheiten erfassen.",
  "id": "31b3d5f7-9a1c-4e3b-8d5f-7a9c1e3b5d40",
  "locked": false,
  "memberCount": 4,
  "name": "Service Desk",
  "permissions": [
    "desk:read",
    "desk:write",
    "hr:absence:request",
    "hr:time:record",
    "tenant:access",
    "tenant:knowledge:read"
  ],
  "version": 2
}
```

### Responses

- **201** Created (`application/json`)
- **400** Error (`application/json`)
- **403** Error (`application/json`)

Fields of the 201 answer:

- `name` (string, required): Name of the role
- `description` (string): Description of the role
- `id` (string): Id of the role
- `key` (string, read-only): Stable key of the role
- `locked` (boolean, read-only): Built-in role whose permissions cannot be changed
- `memberCount` (integer, read-only): Number of employees holding the role
- `permissions` (array of string): Permissions of the role
- `systemKey` (string, read-only): Key of a built-in role, empty for roles of the tenant
- `version` (integer): Version for optimistic locking: send the version you read with a change (stale: 409 version_conflict)

Example 201 answer:

```json
{
  "description": "Tickets bearbeiten, Wissen lesen, eigene Zeiten und Abwesenheiten erfassen.",
  "id": "31b3d5f7-9a1c-4e3b-8d5f-7a9c1e3b5d40",
  "locked": false,
  "memberCount": 4,
  "name": "Service Desk",
  "permissions": [
    "desk:read",
    "desk:write",
    "hr:absence:request",
    "hr:time:record",
    "tenant:access",
    "tenant:knowledge:read"
  ],
  "version": 2
}
```

### Example request

```bash
curl -X POST 'https://api.mbcom.cloud/api/hr/v1/roles' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"description":"Tickets bearbeiten, Wissen lesen, eigene Zeiten und Abwesenheiten erfassen.","id":"31b3d5f7-9a1c-4e3b-8d5f-7a9c1e3b5d40","locked":false,"memberCount":4,"name":"Service Desk","permissions":["desk:read","desk:write","hr:absence:request","hr:time:record","tenant:access","tenant:knowledge:read"],"version":2}'
```
