## Create an org unit (hr:admin)

`POST /api/hr/v1/org-units`

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

The parent must be an active unit; nesting is limited to 12 levels. Heads and deputies that would make the chain of command loop are rejected (`400`, field `headId`).

### Request body

`application/json` (required)

- `name` (string, required): Name of the unit (max length 120)
- `archived` (boolean): Archived: no longer offered for new data, kept for existing data
- `deputyId` (string): Stands in for the head (decides while the head is away)
- `headId` (string): Employee who leads the unit (direct manager of its members)
- `id` (string, read-only): Id of the org unit
- `memberCount` (integer, read-only): Active employees placed directly in the unit
- `parentId` (string): Empty = top level
- `sortOrder` (integer): Position in lists (ascending)
- `version` (integer): Version for optimistic locking: send the version you read with a change (stale: 409 version_conflict)

Example:

```json
{
  "archived": false,
  "deputyId": "e5a1c3d7-2b4f-4c6e-8a0b-1d3f5b7c9e02",
  "headId": "b2d4f6a8-0c1e-4a3b-9d5f-7e9a1c3b5d04",
  "id": "0c2e4a6c-8e0a-4c2e-9a4c-6e8a0c2e4a71",
  "memberCount": 4,
  "name": "Service Desk",
  "parentId": "2e4a6c8e-0a2c-4e4a-8c6e-0a2c4e6a8c72",
  "sortOrder": 10,
  "version": 2
}
```

### Responses

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

Fields of the 201 answer:

- `name` (string, required): Name of the unit (max length 120)
- `archived` (boolean): Archived: no longer offered for new data, kept for existing data
- `deputyId` (string): Stands in for the head (decides while the head is away)
- `headId` (string): Employee who leads the unit (direct manager of its members)
- `id` (string, read-only): Id of the org unit
- `memberCount` (integer, read-only): Active employees placed directly in the unit
- `parentId` (string): Empty = top level
- `sortOrder` (integer): Position in lists (ascending)
- `version` (integer): Version for optimistic locking: send the version you read with a change (stale: 409 version_conflict)

Example 201 answer:

```json
{
  "archived": false,
  "deputyId": "e5a1c3d7-2b4f-4c6e-8a0b-1d3f5b7c9e02",
  "headId": "b2d4f6a8-0c1e-4a3b-9d5f-7e9a1c3b5d04",
  "id": "0c2e4a6c-8e0a-4c2e-9a4c-6e8a0c2e4a71",
  "memberCount": 4,
  "name": "Service Desk",
  "parentId": "2e4a6c8e-0a2c-4e4a-8c6e-0a2c4e6a8c72",
  "sortOrder": 10,
  "version": 2
}
```

### Example request

```bash
curl -X POST 'https://api.mbcom.cloud/api/hr/v1/org-units' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"archived":false,"deputyId":"e5a1c3d7-2b4f-4c6e-8a0b-1d3f5b7c9e02","headId":"b2d4f6a8-0c1e-4a3b-9d5f-7e9a1c3b5d04","id":"0c2e4a6c-8e0a-4c2e-9a4c-6e8a0c2e4a71","memberCount":4,"name":"Service Desk","parentId":"2e4a6c8e-0a2c-4e4a-8c6e-0a2c4e6a8c72","sortOrder":10,"version":2}'
```
