Create or update department
Updated date: 01/10/2026
Updated by: VNPT eContract's team
Purpose
The function creates new departments or updates existing departments identified by department code. Multiple departments can be processed in one request.
- Request URL:
/api/departments/create-or-update - HTTP method:
POST - HTTP content-type:
application/json - Authorize:
Bearer token - Parameter:
The request body is an array of department objects with the following fields:
| Key | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Unique department code. If the code already exists, the corresponding department is updated. |
name | string | Yes | Department name. |
description | string | No | Department description. |
sharingAccessPermission | boolean | No | Whether users in the department share access permissions. |
userCodes | Array[string] | No | Codes of users assigned to the department. |
Sample request
[
{
"code": "HR",
"name": "Human Resources",
"description": "",
"sharingAccessPermission": false,
"userCodes": ["USER01"]
},
{
"code": "IT",
"name": "Information Technology",
"description": "",
"sharingAccessPermission": false,
"userCodes": []
}
]
Sample response body
{
"data": [
{
"id": 12012,
"name": "Human Resources",
"code": "HR",
"userCount": 1,
"sharingAccessPermission": false,
"users": [],
"requireApproval": false
},
{
"id": 12013,
"name": "Information Technology",
"code": "IT",
"userCount": 0,
"sharingAccessPermission": false,
"users": [],
"requireApproval": false
}
],
"success": true,
"code": 0,
"messages": [
"Create 2 department success, update 0 department success."
]
}
Response Body Description
| Key | Type | Description |
|---|---|---|
success | boolean | Response status (true: Success, false: Failure). |
code | int | Response code from the system. |
messages | array | List of messages summarizing the number of departments created and updated. |
data | array | List of newly created or updated departments (see details below). |
Details of objects in the data array:
| Key | Type | Description |
|---|---|---|
id | int | Department ID. |
name | string | Department name. |
code | string | Department code. |
userCount | int | Number of users assigned to the department. |
sharingAccessPermission | boolean | Whether users in the department share access permissions. |
users | array | List of users in the department. |
requireApproval | boolean | Whether approval is required for the department. |