Skip to main content

Departments Domain

The Departments domain provides endpoints for managing departments within a client organization. Departments are organizational groupings that users can be assigned to. A user can belong to multiple departments.

For embedding and endpoint design decisions, see the Design Guidelines.

Endpoints

EndpointMethodDescription
List DepartmentsGETPaginated list of departments. Use for tables and dropdowns.
Get DepartmentGETFetch a single department directly by ID.
Create DepartmentPOSTCreate a new department.
Update DepartmentPATCHUpdate a department's name or description.
Delete DepartmentDELETEDelete a department.
Add MembersPOSTAdd users to a department (bulk).
Remove MembersPOSTRemove users from a department (bulk).

Getting Users in a Department

To retrieve users belonging to a department, use the List Users endpoint with the department_id filter:

GET /clients/{client_id}/users?department_id=d1a2b3c4-e5f6-7890-abcd-ef1234567890

Users are not embedded in department responses because departments can have hundreds or thousands of members -- an unbounded, paginated relationship. See Why users are not embedded below.

Data Transfer Objects (DTOs)

DepartmentRef

Minimal department reference for embedding inside other domain responses (e.g. User.departments). No joins required beyond the departments table.

{
"id": "d1a2b3c4-e5f6-7890-abcd-ef1234567890",
"name": "Engineering",
"description": "Software development and infrastructure teams"
}
FieldTypeNullableDescription
idstring (uuid)NoStable unique identifier for the department
namestringNoDepartment display name
descriptionstringYesOptional department description

DB source: departments.id, departments.name, departments.description

Used in: Embedded inside User.departments. See Users domain.


Department

Full department representation returned by all department-primary endpoints. Extends DepartmentRef with member count and audit timestamps.

{
"id": "d1a2b3c4-e5f6-7890-abcd-ef1234567890",
"name": "Engineering",
"description": "Software development and infrastructure teams",
"member_count": 45,
"created_at": "2026-02-05T21:29:34.214Z",
"updated_at": "2026-02-05T21:29:34.214Z"
}
FieldTypeNullableDescription
All DepartmentRef fieldsid, name, description -- see DepartmentRef
member_countintegerNoNumber of users currently assigned to this department
created_atstring (ISO 8601)NoWhen this department record was first created
updated_atstring (ISO 8601)NoWhen this department record was last modified

DB source:

DTO FieldDB Source
(DepartmentRef fields)see DepartmentRef
member_countCOUNT(*) from user_departments where department_id = ? AND deleted_at IS NULL
created_atdepartments.created_at
updated_atdepartments.updated_at

Omitted internal fields: client_id (in URL path), created_by, updated_by, deleted_at, deleted_by

Used in: List Departments, Get Department, Create Department, Update Department


BulkMemberResult

Response shape for Add Members and Remove Members. Always returns 200 OK -- individual failures are reported inline rather than as HTTP errors.

{
"succeeded": [
"a1d97031-04e2-4907-a249-093f7436207b",
"b2e08142-15f3-5018-b350-104g8547318c"
],
"failed": [
{
"id": "ffffffff-ffff-ffff-ffff-ffffffffffff",
"error": "User not found"
}
]
}
FieldTypeDescription
succeededstring[]IDs of users successfully added or removed
failedobject[]Users that could not be processed
failed[].idstring (uuid)The user ID that failed
failed[].errorstringHuman-readable reason for the failure

Both add and remove are idempotent: adding a user already in the department or removing a user not in the department both count as succeeded.


Why users are not embedded

Department does not include a users array. This is intentional:

RelationshipCardinalityStrategyReason
User → Departments1:few (1–3)Embed DepartmentRef[] in UserBounded, always needed, static reference
Department → Users1:many (100s–1000s)GET /users?department_id=Unbounded, needs pagination

To get users in a department:

GET /clients/{client_id}/users?department_id=d1a2b3c4-e5f6-7890-abcd-ef1234567890

This supports all the standard List Users filters and pagination alongside the department filter.