## Change, move or archive an org unit (hr:admin)

`PUT /api/hr/v1/org-units/{id}`

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

A unit with members or active sub-units cannot be archived (`409 in_use`). Sends the `version` read.

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | string (uuid) | yes |  |

### 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

- **200** Saved (`application/json`)
- **400** Error (`application/json`)
- **404** Error (`application/json`)
- **409** Error (`application/json`)

Fields of the 200 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 200 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 PUT 'https://api.mbcom.cloud/api/hr/v1/org-units/3f2b8c1e-7d4a-4e9b-9c2a-5b1d6e8f0a12' \
  -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}'
```
