Departments
Departments represent organizational units within a client account, allowing for better organization and tracking of business activities.
Endpoints
List Departments
GET /api/v2/departments
Retrieves a paginated list of departments.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| client_account_id | integer | No | Filter departments by client account |
| is_active | boolean | No | Filter by active status (default: true). Pass null to include all |
| page | integer | No | Page number (default: 1) |
| per_page | integer | No | Items per page (default: 50) |
| with | string | No | Include related resources (supported: client_account) |
Response
{
"data": [
{
"id": 123,
"name": "Sales Department",
"client_account_id": 456,
"sequence_number": 1,
"is_active": true,
"autonomy_level": null,
"created_at": "2024-03-15T10:00:00Z",
"updated_at": "2024-03-15T10:00:00Z",
"created_by_id": 789,
"updated_by_id": 789,
"client_account": {
"id": 456,
"unique_name": "company-abc",
"display_name": "Company ABC"
}
}
],
"meta": {
"page": 1,
"pages": 1,
"per_page": 50,
"records": 1
}
}
The client_account field is only included when with=client_account is in the query.
Department Attributes
| Attribute | Type | Description |
|---|---|---|
| id | integer | Unique identifier (read-only) |
| client_account_id | integer | The client account the department belongs to. Required on create; cannot be changed after creation |
| name | string | Human-readable department name |
| sequence_number | integer | Auto-assigned sequence number within the client account (read-only) |
| is_active | boolean | Whether the department is active. false after deactivation via DELETE |
| autonomy_level | string | Optional autonomy level marker for the department. Used to indicate the degree of operational independence (e.g. for branch reporting) |
| created_at | string | Creation timestamp (ISO 8601, read-only) |
| created_by_id | integer | ID of the creating user (read-only) |
| updated_at | string | Last update timestamp (ISO 8601, read-only) |
| updated_by_id | integer | ID of the user who last updated the department (read-only) |
Get Department
GET /api/v2/departments/{id}
Retrieves a specific department by ID.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| with | string | No | Include related resources (supported: client_account) |
Response
{
"id": 123,
"name": "Sales Department",
"client_account_id": 456,
"sequence_number": 1,
"is_active": true,
"created_at": "2024-03-15T10:00:00Z",
"updated_at": "2024-03-15T10:00:00Z",
"created_by_id": 789,
"updated_by_id": 789
}
Create Department
POST /api/v2/departments
Creates a new department.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | The name of the department |
| client_account_id | integer | Yes | The ID of the client account |
Example Request
{
"name": "Sales Department",
"client_account_id": 456
}
Response
{
"id": 123,
"name": "Sales Department",
"client_account_id": 456,
"sequence_number": 1,
"is_active": true,
"created_at": "2024-03-15T10:00:00Z",
"updated_at": "2024-03-15T10:00:00Z",
"created_by_id": 789,
"updated_by_id": 789
}
Update Department
PUT|POST /api/v2/departments/{id}
Updates an existing department. Only name, is_active, and autonomy_level can be modified. client_account_id cannot be changed after creation.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | No | The new name for the department |
| is_active | boolean | No | Set to true to reactivate, or false to deactivate. Deactivating runs the same balance validation as DELETE |
| autonomy_level | string | No | Update the department’s autonomy level |
Example Request
{
"name": "Updated Department Name",
"autonomy_level": "INDEPENDENT"
}
Response
{
"id": 123,
"name": "Updated Department Name",
"client_account_id": 456,
"sequence_number": 1,
"is_active": true,
"created_at": "2024-03-15T10:00:00Z",
"updated_at": "2024-03-15T15:30:00Z",
"created_by_id": 789,
"updated_by_id": 789
}
Deactivate Department
DELETE /api/v2/departments/{id}
Deactivates a department by setting its is_active status to false. The department record is preserved for historical purposes.
Response
{
"id": 123,
"name": "Sales Department",
"client_account_id": 456,
"sequence_number": 1,
"is_active": false,
"created_at": "2024-03-15T10:00:00Z",
"updated_at": "2024-03-15T16:00:00Z",
"created_by_id": 789,
"updated_by_id": 789
}
Deactivation Validation
When attempting to deactivate a department, the system performs validation to ensure data integrity:
- Balance Checking: The system checks if any accounting accounts with mandatory department dimensions have non-zero balances for this specific department.
- Validation Failure: If any accounts have non-zero balances, the deactivation is denied with a 400 Bad Request error.
- Error Details: The error message includes specific account codes and their balances to help identify which transactions need to be resolved.
Example Error Response
{
"error": "Cannot deactivate department: account 4000: 8500.00, account 5000: -1200.00",
"status": 400
}
This validation ensures that departments cannot be deactivated while they still have outstanding balances, maintaining the integrity of your accounting records.
Error Responses
| Status Code | Description |
|---|---|
| 400 | Invalid request (e.g., missing required fields) |
| 403 | Forbidden (no access to client account) |
| 404 | Department not found |
Business Rules
- Departments are associated with a specific client account
- Users must have access to the client account to manage its departments
- The client_account_id cannot be changed after department creation
- Each department is automatically assigned a unique sequence number within its client account
- Creation and update timestamps and user IDs are automatically tracked
Common Use Cases
- Creating organizational structure within a company
- Tracking activities by department
- Managing departmental resources
- Organizing reporting by business unit
Best Practices
- Use clear and descriptive department names
- Maintain consistent naming conventions
- Consider the organizational hierarchy when creating departments
- Use the sequence_number for internal reference