logo

Get Department List

This interface is used to obtain the department list information under the current company.

Request Method

GET /departments

Request Parameters

None

Response Data

Attribute NameTypeDescription
codeIntegerExecution result code, 1000 represents success
departmentsArraySee details below
Structure of departments
Parameter NameTypeDescription
idIntegerDepartment ID
nameStringDepartment name
sub_departmentArraySub-departments

Example

Request

curl https://demo.udesk.cn/open_api_v1/departments?email=admin@udesk.cn&timestamp=1494474404&sign=6892f1b794071c260e1b1eac15df588fc919c9e86eb742affaa742ad6c03cb52&nonce=2d931510-d99f-494a-8c67-87feb05e1594&sign_version=v2 \
-X GET \
-H 'content-type: application/json'

Response

{
    "code": 1000,
    "departments": [
        {
            "id": 1,
            "name": "Department 1",
            "sub_department": [
                {
                    "id": 10,
                    "name": "Sub-department 1",
                    "sub_department": [ {"id": 11, "name": "Sub-department 2", "sub_department": []} ]
                },
                {
                    "id": 11,
                    "name": "Sub-department 2",
                    "sub_department": []
                }
            ]
        },
        {
            "id": 2,
            "name": "Department 2",
            "sub_department": []
        },
        {
            "id": 3,
            "name": "Department 3",
            "sub_department": []
        }
    ]
}

Create Department

This interface is used to create a department.

Request Method

POST /departments

Request Parameters (request body)

ParameterRequiredTypeDescriptionRestrictionsDefault
nameYesStringDepartment nameNo more than 255 characters
parent_idNoIntegerParent department ID0
Note: parent_id is the ID of the parent department. If not entered, the default is 0. When parent_id is 0, it means the parent department does not exist.

Response Data

Attribute NameTypeDescription
codeIntegerExecution result code, 1000 represents success
idIntegerID of the department created successfully

Example

Request

curl https://demo.udesk.cn/open_api_v1/departments?email=admin@udesk.cn&timestamp=1494474404&sign=6892f1b794071c260e1b1eac15df588fc919c9e86eb742affaa742ad6c03cb52&nonce=2d931510-d99f-494a-8c67-87feb05e1594&sign_version=v2 \
-X POST \
-H 'content-type: application/json' \
-d '
{
  "name": "Department 12",
  "parent_id": 1
}'

Response

{
    "code": 1000,
    "id": 5
}

Edit Department

This interface is used to edit the basic information of an existing department.

Request Method

PUT /departments/:id

Request Parameters (url)

Parameter NameTypeRequiredDescriptionRestrictions
idIntegerYesDepartment ID

Request Parameters (request body)

ParameterRequiredTypeDescriptionRestrictionsDefault
nameYesStringDepartment nameNo more than 255 characters
Note: This interface can only modify the name of the department based on the id, and cannot modify the parent_id of the department, that is, it cannot change the hierarchical relationship of the department. Even if parent_id is added in the request parameters, it will not take effect and there will be no error message.

Response Data

Attribute NameTypeDescription
codeIntegerExecution result code, 1000 represents success
departmentObjectDepartment information, structure as follows

Structure of department

Parameter NameTypeDescription
idIntegerDepartment ID
nameStringDepartment name
parent_idIntegerParent department ID

Example

Request

curl https://demo.udesk.cn/open_api_v1/departments/5?email=admin@udesk.cn&timestamp=1494474404&sign=6892f1b794071c260e1b1eac15df588fc919c9e86eb742affaa742ad6c03cb52&nonce=2d931510-d99f-494a-8c67-87feb05e1594&sign_version=v2 \
-X PUT \
-H 'content-type: application/json' \
-d '{"name": "New Department 12"}'

Response

{
    "code": 1000,
    "department": {
      "id": 5,
      "name": "New Department 12",
      "parent_id": 1
    }
}

Delete Department

This interface is used to delete an existing department.

Request Method

DELETE /departments/:id

Request Parameters (url)

Parameter NameTypeRequiredDescriptionRestrictions
idIntegerYesDepartment ID

Request Parameters (request body)

None

Response Data

Attribute NameTypeDescription
codeIntegerExecution result code, 1000 represents success
messageStringExecution result explanation

Example

Request

curl https://demo.udesk.cn/open_api_v1/departments/5?email=admin@udesk.cn&timestamp=1494474404&sign=6892f1b794071c260e1b1eac15df588fc919c9e86eb742affaa742ad6c03cb52&nonce=2d931510-d99f-494a-8c67-87feb05e1594&sign_version=v2 \
-X DELETE \
-H 'content-type: application/json'

Response

{
    "code": 1000,
    "message": "Department with ID 5 deleted successfully"
}

Error Code Description

Error CodeMessage InformationException:message InformationDescription
2000Unknown errorVerification failed: Name already in useThe name has already been used
Non-existent parent department with parent_id xxxThe parent department with the provided parent_id xxx does not exist
The provided parent_id is not a non-negative integerThe format of the provided parent_id is incorrect; it is not a non-negative integer
The resource was not foundThe department to be edited was not found based on the provided id; it may not exist or the id format is incorrect
2015Non-administrators cannot operateNon-administrators cannot operateThe email address used to call the interface must be an administrator's email; non-administrators cannot perform operations
2059Open API signature is incorrectOpen API signature is incorrectThe Open API signature is incorrect. For details, refer to the documentation in the Authentication section