> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a department

> Call this API to update information for a specified department, including configuration fields such as department name, parent department, and visibility.

Call this API to update the information of a department.

## Request

| **Basic information** |                                                                                                            |
| --------------------- | ---------------------------------------------------------------------------------------------------------- |
| HTTP URL              | [https://api.dingtalk.io/topapi/v2/department/update](https://api.dingtalk.io/topapi/v2/department/update) |
| HTTP Method           | POST                                                                                                       |
| Supported app type    | appType-Internal app                                                                                       |
| Required permissions  | permission-qyapi\_manage\_addresslist-Contacts data management permission                                  |

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                    |
| ------------- | ------ | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | bE74xxxx | The app credential used to call this API. Obtain it through the API for getting the [access\_token of an internal app](/open/development/obtain-orgapp-token). |

### Request body

| Name                         | Type    | Required | Example                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                |
| ---------------------------- | ------- | -------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| dept\_id                     | Number  | Yes      | 100                         | The department ID. You can call the [Get department list](/open/development/user-management-acquires-the-list-departments) API to obtain the value of dept\_id.                                                                                                                                                                                                                                                            |
| parent\_id                   | Number  | No       | 2                           | The parent department ID. The root department ID is 1. You can call the [Get department list](/open/development/user-management-acquires-the-list-departments) API to obtain the value of parent\_id.                                                                                                                                                                                                                      |
| hide\_dept                   | Boolean | No       | true                        | Whether to hide this department:   - **true**: hide the department.  After being hidden, the department will not appear in the company contacts. - **false**: show the department.   If no value is passed, the current setting remains unchanged.                                                                                                                                                                         |
| dept\_permits                | String  | No       | 123,456                     | The list of other departments that are allowed to view this department.  This value takes effect when **hide\_dept** is set to **true**.  **Note**  The total count of this list plus the user\_permits list cannot exceed 50.                                                                                                                                                                                             |
| user\_permits                | String  | No       | user123,manager222          | The list of user IDs that are allowed to view this department.  This value takes effect when **hide\_dept** is set to **true**.  **Note**  The total count of this list plus the dept\_permits list cannot exceed 50.                                                                                                                                                                                                      |
| create\_dept\_group          | Boolean | No       | true                        | Whether to create an organization chat associated with this department. The default value is false, meaning that no chat is created.  If no value is passed, the current setting remains unchanged.                                                                                                                                                                                                                        |
| order                        | Number  | No       | 10                          | The sort value within the parent department. A smaller order value ranks higher.                                                                                                                                                                                                                                                                                                                                           |
| name                         | String  | No       | HR                          | The department name. The length must be 1 to 64 characters. The characters '-', '，', and ',' are not allowed.                                                                                                                                                                                                                                                                                                              |
| source\_identifier           | String  | No       | HR Department               | The department identifier field. Developers can use this field to uniquely identify a department and map it to a department in external DingTalk contacts.  **Note**  This field is not visible in the department information in the organization management console.                                                                                                                                                      |
| outer\_dept                  | Boolean | No       | true                        | Whether to restrict members of this department from viewing the contacts:   - **true**: enable the restriction. Once enabled, members of this department can only view contacts within the specified scope. - **false**: no restriction.   If no value is passed, the current setting remains unchanged.                                                                                                                   |
| outer\_permit\_users         | String  | No       | user123,manager123          | The list of user IDs in the contacts that members of this department are allowed to view.  This parameter takes effect when **outer\_dept** is set to **true**.  **Note**  The total count of this list plus the outer\_permit\_depts list cannot exceed 50.                                                                                                                                                               |
| outer\_permit\_depts         | String  | No       | 123,456                     | The list of department IDs in the contacts that members of this department are allowed to view.  This parameter takes effect when **outer\_dept** is set to **true**.  **Note**  The total count of this list plus the outer\_permit\_users list cannot exceed 50.                                                                                                                                                         |
| outer\_dept\_only\_self      | Boolean | No       | true                        | Whether members of this department can only view the contacts of their own department and sub-departments:   - **true**: can only view the contacts of their own department and sub-departments. - **false**: cannot view all contacts, and can only see themselves in the contacts.   This parameter takes effect when **outer\_dept** is set to **true**.  If no value is passed, the current setting remains unchanged. |
| language                     | String  | No       | zh\_CN                      | The contacts language:   - **zh\_CN**: Chinese. - **en\_US**: English.                                                                                                                                                                                                                                                                                                                                                     |
| auto\_add\_user              | Boolean | No       | false                       | After the department chat has been created, whether new members joining the department are automatically added to the chat:   - **true**: automatically join the chat. - **false**: do not automatically join the chat.   If no value is passed, the current setting remains unchanged.                                                                                                                                    |
| auto\_approve\_apply         | Boolean | No       | false                       | Whether to automatically approve requests to join this department:   - **true:** requests to join this department are approved automatically. - **false:** requests to join this department must be approved by an admin with the relevant permissions.                                                                                                                                                                    |
| dept\_manager\_userid\_list  | String  | No       | manager220                  | The list of user IDs of the department managers. Separate multiple user IDs with commas.  **Note**  Department managers must be members of the current department. Otherwise, the API returns the error **userId does not exist**.                                                                                                                                                                                         |
| group\_contain\_sub\_dept    | Boolean | No       | true                        | Whether the department chat includes sub-departments:   - **true**: include. - **false**: do not include.   If no value is passed, the current setting remains unchanged.                                                                                                                                                                                                                                                  |
| group\_contain\_outer\_dept  | Boolean | No       | true                        | Whether the department chat includes outsourced departments:   - **true**: include. - **false**: do not include.   If no value is passed, the current setting remains unchanged.  **Note**  An outsourced department can only see its own department, and cannot see other departments or other people.                                                                                                                    |
| group\_contain\_hidden\_dept | Boolean | No       | true                        | Whether the department chat includes hidden departments:   - **true**: include. - **false**: do not include.   If no value is passed, the current setting remains unchanged.                                                                                                                                                                                                                                               |
| org\_dept\_owner             | String  | No       | 100                         | The user ID of the organization chat owner.  **Note**  The group owner must be a member of the current department.                                                                                                                                                                                                                                                                                                         |
| force\_update\_fields        | String  | No       | dept\_manager\_userid\_list | The fields to be force-updated. This supports clearing specified fields. Separate multiple fields with commas. The currently supported field is: `dept_manager_userid_list`.                                                                                                                                                                                                                                               |
| code                         | String  | No       | 10000                       | The department code. The maximum length is 30 characters.  **Note**  This field can only be set through this API.                                                                                                                                                                                                                                                                                                          |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/department/update" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=c6391xxxxb574' \
-d 'dept_id=100' \
-d 'parent_id=2' \
-d 'hide_dept=true' \
-d 'user_permits=100%2C200'
-d 'dept_permits=3%2C4%2C5' \
-d 'language=zh_CN' \
-d 'code=10000'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/update");
OapiV2DepartmentUpdateRequest req = new OapiV2DepartmentUpdateRequest();
req.setDeptId(100L);
req.setParentId(2L);
req.setOuterDept(true);
req.setHideDept(true);
req.setCreateDeptGroup(true);
req.setOrder(10L);
req.setName("HR");
req.setSourceIdentifier("HR Department");
req.setDeptPermits("123,456");
req.setUserPermits("user123,manager222");
req.setOuterPermitUsers("user100,user200");
req.setOuterPermitDepts("123,456");
req.setOuterDeptOnlySelf(true);
req.setLanguage("zh_CN");
req.setAutoAddUser(false);
req.setDeptManagerUseridList("manager200");
req.setGroupContainSubDept(true);
req.setGroupContainOuterDept(true);
req.setGroupContainHiddenDept(true);
req.setOrgDeptOwner("100");
OapiV2DepartmentUpdateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

req=dingtalk.api.OapiV2DepartmentUpdateRequest("https://api.dingtalk.io/topapi/v2/department/update")

req.dept_id=100
req.parent_id=2
req.hide_dept=true
req.user_permits="100,200"
req.dept_permits="3,4,5"
req.language="zh_CN"
req.code="10000"
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiV2DepartmentUpdateRequest;
$req->setDeptId("100");
$req->setParentId("2");
$req->setHideDept("true");
$req->setDeptPermits("3,4,5");
$req->setUserPermits("100,200");
$req->setLanguage("zh_CN");
$req->setCode("10000");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/update");
OapiV2DepartmentUpdateRequest req = new OapiV2DepartmentUpdateRequest();
req.DeptId = 100L;
req.ParentId = 2L;
req.HideDept = true;
req.DeptPermits = "3,4,5";
req.UserPermits = "100,200";
req.Language = "zh_CN";
req.Code = "10000";
OapiV2DepartmentUpdateResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Response

### Response body

| Name        | Type   | Example      | Description                         |
| ----------- | ------ | ------------ | ----------------------------------- |
| errcode     | Number | 0            | The return code.                    |
| errmsg      | String | ok           | The description of the return code. |
| request\_id | String | 6iq4zcul5zjp | The request ID.                     |

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
 "errcode":0,
 "errmsg":"ok",
 "request_id": "6iq4zcul5zjp"
}
```

### Error codes

If an error is returned when you call this API, refer to the [Global error codes](/open/development/server-api-error-codes-1) documentation to find a solution based on the error message.

| Error code (errcode) | Error message (errmsg)                | Solution                                                                           |
| -------------------- | ------------------------------------- | ---------------------------------------------------------------------------------- |
| 43007                | Insufficient permissions              | Confirm whether the access\_token has the required permissions for this operation. |
| 40009                | Invalid department ID                 | Confirm whether the dept\_id is correct.                                           |
| 60018                | The root department cannot be updated | Use a different dept\_id.                                                          |
| 60003                | The department was not found          | Confirm whether the dept\_id is correct.                                           |
| 60001                | Invalid department name               | Confirm whether the department name is correct.                                    |
| 40011                | Invalid order                         | Confirm whether the order value is valid.                                          |
| 60004                | The parent department does not exist  | Confirm whether the parent\_id is correct.                                         |
| 60010                | A loop exists in the department IDs   | Reset the department ID.                                                           |
| 60109                | Invalid viewable ID list              | Verify whether the viewable list is valid.                                         |
| 40031                | Invalid userId list                   | Confirm whether the userId is correct.                                             |
| 40093                | Invalid organization chat owner       | Confirm whether the user ID of the organization chat owner is correct.             |
| 60510                | Failed to set department permissions  | Verify whether the parameters are valid.                                           |
| -1                   | System busy                           | Try again later.                                                                   |
