Department
Department List
Request Parameters
name | type | required | description |
id | number | no | department id |
Sample Response data:
Description:
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
departments | array | yes | department list |
id | number | yes | department id |
name | string | yes | department name |
parentid | number | yes | parent department id, root department will be 1 |
order | number | yes | order within parent department, larger number is before smaller number |
Department User List
Description
name | type | required | description |
departmentId | number | yes | department id |
Sample Response data:
Description
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
user_list | array | yes | department user list |
user_list.userid | string | yes | corp user id |
user_list.name | string | yes | corp user name |
user_list.department | array | yes | departments that the corp user belong to |
Create Department
Sample Request Data:
Description:
name | type | required | description |
id | number | no | department id, if this is empty, the department id will be generated automatically |
name | string | no | department name, can not be duplicate within same parent department |
name_en | string | no | english name for the department |
parentid | number | no | parent department id of the current department |
Sample Response data:
Description:
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
id | number | yes | department id |
Error Code
code | description |
60008 | department already exist |
-1 | failed to create the department |
Update Department
Sample Request Data:
Description:
name | type | required | description |
id | number | yes | department id |
name | string | no | department name |
name_en | string | no | department english name |
parentid | number | no | parent department id |
Sample Response data:
Description:
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
WARNING
To update parentid
, move department, you need to grant internal app 【句子助手】 with permission to the parent department.
Error Code
code | description |
-2 | failed to update the department |
Delete Department
Sample Request Data:
Description:
name | type | required | description |
id | number | yes | department id |
Sample Response data:
Description:
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
WARNING
- Can not delete root department
- Can not delete department with child department or corp users
Batch Update Department Users
Sample Request Data:
Description
name | type | required | description |
user_list | array | yes | corp user list to be updated |
user_list.userid | string | yes | corp user id |
user_list.department | array | yes | department id list |
Sample Response data:
Description:
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
fail_list | array | yes | update failed list |
fail_list.userid | string | yes | corp user id |
fail_list.department | array | yes | department id list |
fail_list.errcode | number | yes | error code from WeCom |
fail_list.errmsg | string | yes | error message from WeCom |
Batch Create/Update Department
Sample Request Data:
Description
name | type | required | description |
departments | array | yes | departments to be updated |
departments.id | number | yes | department id |
departments.parentid | number | yes | parent department id |
departments.name | string | yes | department name |
departments.order | number | no | department order, empty or 0 will leave the order unchanged |
Sample Response data:
Description
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
jobId | string | yes | async update department job id |
WARNING
- If a department is in the update list exists, will do update on the department
- If a department is in the update list does not exist, will do insert
- If a department is not in the update list, but in WeCom, and there is no child department or users in the department, will do delete
Error Code
code | description |
-3 | the job existed |
Get Batch Department Update Result
Sample Request Data:
Description
name | type | required | description |
jobId | string | yes | the jobId returned from the batch update department |
Sample Response data:
Description
name | type | required | description |
errcode | number | yes | return code |
errmsg | string | yes | error message |
id | number | yes | department id |