# Modify department information in part

Call this interface to update some information of the specified department, including name, parent department, sorting, person in charge, etc.

## Precautions

- When calling this interface to update department information, all departments involved need to be within the application's contacts permissions, otherwise the call will fail and a no permissions error will be reported. To understand the scope of authority, see [Authority Scope Resource Introduction](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).
- This interface is not a full update interface. If a request parameter is not passed, the corresponding department information will not be modified by default (Note: if an empty array is passed to leaders and department_hrbps, the original value will be cleared). If you need to use the full update interface, please refer to [Update all department information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/update).

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/contact/v3/departments/:department_id
HTTP Method | PATCH
Rate Limit | [1000 per minute & 50 per second](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
Supported app types | Custom App
Required scopes<br>**To use this API, you must have at least 1 of the listed scopes.** | Update Contacts(contact:contact)
Required field scopes | **Notice**：The response body of the API contains the following sensitive fields, and they will be returned only after corresponding scopes are added. If you do not need the fields, it is not recommended that you request the scopes.<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Obtain department's basic information(contact:department.base:readonly)<br>Obtain user ID(contact:user.employee_id:readonly)<br>View department HRBP info(contact:department.hrbp:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)

### Request header

Parameter | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `tenant_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer t-7f1bcd13fc57d46bac21793a18e560"<br>[How to choose and get access token](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | Yes | **Fixed value**: "application/json; charset=utf-8"

### Path parameters

Parameter | Type | Description
---|---|---
department_id | string | Department ID, ID type needs to be consistent with the value of the query parameter department_id_type. Instructions on how to obtain the ID:<br>- After calling the [Create Department](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/create) interface, the department ID information can be obtained from the returned result.<br>- The department API provides multiple ways to obtain the IDs of other departments, such as [Get list of sub-departments](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/children), [Get parent department information]( https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/parent), [search department](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/search), you can choose the appropriate API for querying.<br>**Example value**: "D096"<br>**Data validation rules**:<br>- Maximum length: `64` characters<br>- Regular expression: `^[a-zA-Z0-9][a-zA-Z0-9_\-@.]{0,63}$`

### Query parameters

Parameter | Type | Required | Description
---|---|---|---
user_id_type | string | No | User ID categories<br>**Example value**: open_id<br>**Optional values are**:<br>- open_id：Identifies a user to an app. The same user has different Open IDs in different apps. [How to get Open ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid)<br>- union_id：Identifies a user to a tenant that acts as a developer. A user has the same Union ID in apps developed by the same developer, and has different Union IDs in apps developed by different developers. A developer can use Union ID to link the same user's identities in multiple apps.[How to get Union ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-union-id)<br>- user_id：Identifies a user to a tenant. The same user has different User IDs in different tenants. In one single tenant, a user has the same User ID in all apps （including store apps）. User ID is usually used to communicate user data between different apps. [How to get User ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-user-id)<br>**Default value**: `open_id`<br>**When the value is `user_id`, the following field scopes are required**:<br>Obtain user ID(contact:user.employee_id:readonly)
department_id_type | string | No | The type of department ID in this call. For a detailed introduction to department ID, please refer to [Department ID Description](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/field-overview#23857fe0).<br>**Example value**: open_department_id<br>**Optional values are**:<br>- department_id：Supports user-defined configuration of department IDs. The deleted department_id can be reused when customizing the configuration, so department_id is unique within the scope of the department that has not been deleted.<br>- open_department_id：Department ID automatically generated by the system. The ID prefix is fixed to `od-` and is globally unique within the tenant.<br>**Default value**: `open_department_id`

### Request body

Parameter | Type | Required | Description
---|---|---|---
name | string | No | Department name.<br>**Notice**:<br>- Cannot contain slashes (`/`).<br>- Cannot be the same as the existing department name.<br>**Default value**: empty, indicating no modification.<br>**Example value**: "DemoName"<br>**Data validation rules**:<br>- Minimum length: `1` characters
i18n_name | department_i18n_name | No | International configuration of department names.<br>**Notice**:<br>- Cannot contain slashes (`/`).<br>- It cannot be repeated with the internationalization configuration of the existing department name.<br>**Default value**: empty, indicating no modification.
zh_cn | string | No | Department's Chinese name.<br>**Example value**: "Demo name"
ja_jp | string | No | Department's Japanese name.<br>**Example value**: "Name"
en_us | string | No | Department's English name.<br>**Example value**: "Demo Name"
parent_department_id | string | No | The ID of the parent department. How to obtain department ID:<br>- If the parent department of the department needs to be set as the root department, this parameter takes the value `0`.<br>- You can call the [Search Department](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/search) interface to obtain the required department ID.<br>**Default value**: empty, indicating no modification.<br>**Example value**: "D067"
leader_user_id | string | No | The user ID of the department head. The ID type is consistent with the value of the query parameter user_id_type. For how to obtain user ID, please refer to [How to obtain different user IDs](https://open.feishu.cn/document/home/user-identity-introduction/open-id).<br>**Note**: The values of department head (leader_user_id) and department head (leaderID corresponding to leaderType value 1) are always consistent. therefore:<br>- If the department head is set at the same time (leaderID corresponding to leaderType value 1), the department head set here must be the same person as the department head.<br>- Only the department head is modified, and the department leader will be modified simultaneously (leaderID corresponding to leaderType value 1).<br>**Default value**: empty, indicating no modification.<br>**Example value**: "ou_7dab8a3d3cdcc9da365777c7ad535d62"
order | string | No | The sorting of departments is the order in which departments are displayed among departments at the same level. The value format is a non-negative integer of String type. The smaller the value, the higher the sorting is.<br>**Note**: The order value is unique, that is, the value passed in cannot be the same as the order value of the stock department.<br>**Default value**: empty, indicating no modification.<br>**Example value**: "100"
create_group_chat | boolean | No | Whether to create department groups.<br>**Optional values are:**<br>- true: create.<br>- false: Do not create. If a department group has been created previously, the group will continue to exist even if set to false.<br>**Note**: When creating a department group, the group name defaults to the department name, and the group owner defaults to the department head.<br>**Default value**: empty, indicating no modification.<br>**Example value**: false
leaders | departmentLeader\[\] | No | Department head information.<br>**Notice**:<br>- If an empty array is passed to leaders, the original value will be cleared.<br>- When configuring this parameter, you must specify a person in charge.<br>- When setting up multiple persons in charge, only one person in charge can be set as the main person in charge.<br>- The values of department head (leader_user_id) and department head (leaderID corresponding to leaderType value 1) are always consistent. therefore:<br>- If a department head (leader_user_id) is set at the same time, the department head set here must be the same person as the department head.<br>- Only the department leader is modified, and the department head (leader_user_id) will be modified simultaneously.
leaderType | int | Yes | Person in charge type.<br>**Example value**: 1<br>**Optional values are**:<br>- 1：Main person in charge<br>- 2：Deputy responsible person
leaderID | string | Yes | The user ID and ID type of the person in charge are consistent with the value of the query parameter user_id_type. For how to obtain user ID, please refer to [How to obtain different user IDs](https://open.feishu.cn/document/home/user-identity-introduction/open-id).<br>**Example value**: "ou_7dab8a3d3cdcc9da365777c7ad535d62"
group_chat_employee_types | int\[\] | No | Personnel type restrictions for department groups.<br>The value range of personnel type is as follows. This parameter supports setting multiple type values. If there are multiple types, separate them with English `,`:<br>- 1: Regular employee<br>- 2: Intern<br>- 3: Outsourcing<br>- 4: Labor services<br>- 5: Consultant<br>This parameter supports passing in the number corresponding to the custom person type. You can call the [Query employee type](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/employee_type_enum/list) interface to obtain the corresponding number (enum_value).<br>**Default**: empty<br>**Example value**: [1]
department_hrbps | string\[\] | No | List of user IDs for department HRBP. The ID type is consistent with the value of the query parameter user_id_type. For how to obtain user ID, please refer to [How to obtain different user IDs](https://open.feishu.cn/document/home/user-identity-introduction/open-id).<br>**Notice**: If an empty array is passed to department_hrbps, the original value will be cleared.<br>**Example value**: ["ou_7dab8a3d3cdcc9da365777c7ad535d62"]<br>**Data validation rules**:<br>- Maximum length: `500`

### Request body example
```json
{
    "name": "DemoName",
    "i18n_name": {
        "zh_cn": "Demo name",
        "ja_jp": "Name",
        "en_us": "Demo Name"
    },
    "parent_department_id": "D067",
    "leader_user_id": "ou_7dab8a3d3cdcc9da365777c7ad535d62",
    "order": "100",
    "create_group_chat": false,
    "leaders": [
        {
            "leaderType": 1,
            "leaderID": "ou_7dab8a3d3cdcc9da365777c7ad535d62"
        }
    ],
    "group_chat_employee_types": [
        1
    ],
    "department_hrbps": [
        "ou_7dab8a3d3cdcc9da365777c7ad535d62"
    ]
}
```

**Go Request Example**
```go
import (
	"context"

"github.com/larksuite/oapi-sdk-go/v3"
	"github.com/larksuite/oapi-sdk-go/v3/service/contact/v3"
)

func main() {
	client := lark.NewClient("appID", "appSecret")

req := larkcontact.NewPatchDepartmentReqBuilder().
		DepartmentId(`D096`).
		Department(larkcontact.NewDepartmentBuilder().
			Name(`DemoName`).
			I18nName(larkcontact.NewDepartmentI18nNameBuilder().
				ZhCn(`Demo名称`).
				EnUs(`Demo Name`).
				Build()).
			ParentDepartmentId(`D067`).
			Build()).
		Build()

resp, err := client.Contact.Department.Patch(context.Background(), req)
}
```

**Java Request Example**
```java
import com.lark.oapi.Client;
import com.lark.oapi.service.contact.v3.model.*;
import com.lark.oapi.core.request.RequestOptions;

public class Main {
    public static void main(String arg[]) throws Exception {
        Client client = Client.newBuilder("appId", "appSecret").build();

PatchDepartmentReq req = PatchDepartmentReq.newBuilder()
                .departmentId("D096")
                .department(Department.newBuilder()
                        .name("DemoName")
                        .i18nName(DepartmentI18nName.newBuilder()
                                .zhCn("Demo名称")
                                .enUs("Demo Name")
                                .build())
                        .parentDepartmentId("D067")
                        .build())
                .build();

PatchDepartmentResp resp = client.contact().department().patch(req, RequestOptions.newBuilder().build());
    }
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
department | department | Department information.
name | string | Department name.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
i18n_name | department_i18n_name | Internationalized department name.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
zh_cn | string | Department's Chinese name.
ja_jp | string | Department's Japanese name.
en_us | string | Department's English name.
parent_department_id | string | The department ID of the parent department.<br>- The ID type is consistent with the department_id_type value of the query parameter.<br>- When the parent department is the root department, the parameter value is `0`.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
department_id | string | Custom department ID. This ID can be used later to delete, modify, and query department information.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
open_department_id | string | The open_department_id of the department is automatically generated by the system. This ID can be used later to delete, modify, and query department information.
leader_user_id | string | The user ID and ID type of the department head are consistent with the user_id_type value of the query parameter.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
chat_id | string | The group ID of the department group. You can later use [Get Group Information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/get) to obtain the detailed information of the group.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
order | string | The sorting of departments is the order in which departments are displayed among departments at the same level. The smaller the value, the higher the order.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
unit_ids | string\[\] | List of unit custom IDs bound to the department, currently only one is supported.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
member_count | int | The number of users (including department heads) in the current department and its subordinate departments.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
status | department_status | Department status.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
is_deleted | boolean | Whether it is deleted.<br>**Possible values are:**<br>- true<br>- false
leaders | departmentLeader\[\] | Head of department.
leaderType | int | Person in charge type.<br>**Optional values are**:<br>- 1：Main person in charge<br>- 2：Deputy responsible person
leaderID | string | The user ID and ID type of the person in charge are consistent with the user_id_type value of the query parameter.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
group_chat_employee_types | int\[\] | Personnel type restrictions for department groups. Possible values for person type are as follows:<br>- 1: Regular employee<br>- 2: Intern<br>- 3: Outsourcing<br>- 4: Labor services<br>- 5: Consultant<br>If it is a custom person type, the corresponding number will be returned. You can call the [Query Personnel Type](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/employee_type_enum/list) interface to obtain the custom employee type information corresponding to the corresponding number (enum_value) .
department_hrbps | string\[\] | List of user IDs for department HRBP. The ID type is consistent with the value of the query parameter user_id_type.<br>**Required field scopes**:<br>View department HRBP info(contact:department.hrbp:readonly)
primary_member_count | int | The number of primary members of the current department and its subordinate departments (that is, the member's primary department is the current department).<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)

### Response body example
```json
{
    "code":0,
    "msg":"success",
    "data":{
        "department":{
            "name":"DemoName",
            "i18n_name":{
                "zh_cn":"Demo名称",
                "ja_jp":"デモ名",
                "en_us":"Demo Name"
            },
            "parent_department_id":"D067",
            "department_id":"D096",
            "open_department_id":"od-4e6ac4d14bcd5071a37a39de902c7141",
            "leader_user_id":"ou_7dab8a3d3cdcc9da365777c7ad535d62",
            "chat_id":"oc_5ad11d72b830411d72b836c20",
            "order":"100",
            "unit_ids":[
                "custom_unit_id"
            ],
            "member_count":100,
            "status":{
                "is_deleted":false
            },
            "leaders":[
                {
                    "leaderID":"ou_357368f98775f04bea02afc6b1d33478",
                    "leaderType":1
                }
            ],
            "department_hrbps":[
                "ou_7dab8a3d3cdcc9da365777c7ad535d62",
                "ou_7dab8a3d3cdcc9da365777c7ad535d63"
            ]
        }
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
400 | 43005 | duplicate order error | The value of order is repeated. The order parameter value of the department must be unique and cannot be the same as the order value of the existing department. You can update the order value and try again.
400 | 40002 | process root dept error | Operation on the root department is not supported. Please check whether the root department ID `0` is passed in the request parameter department ID.
400 | 40003 | internal error | Internal error, please obtain the X-Request-Id of the request and provide feedback to [Technical Support](https://applink.feishu.cn/TLJpeNdW).
403 | 40004 | no dept authority error | The departments involved in the current operation need to be within the permission scope of the application contacts. For more information, please refer to [Permission Scope Resource Introduction](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).
400 | 40008 | dept Info is null error | Department information cannot be empty.
403 | 40014 | no parent dept authority error | There is no parent department permission. The parent department passed in needs to be within the address book permission scope of the application. For how to set the address book permission scope, see [Introduction to permission scope resources](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).
401 | 42008 | tenant id is invalid error | Invalid tenant identity. When requesting, the tenant identity corresponding to the Authorization request header needs to be the tenant to which the resource in the current operation belongs.
400 | 43016 | leaders is repeat | The department head is duplicated. Please check whether the department head entered is correct.
400 | 43017 | relate dept over limit | The specified unit has been associated with 1000 departments and cannot be associated with any more departments. If you must associate the current department with the unit, please first call the [Unbind the Department and Unit Binding Relationship](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/unit/unbind_department) interface to unbind another department in the unit and try again.
400 | 43018 | duplicate i18n name | Duplicate internationalization configuration for department name. You need to modify the i18n_name parameter configuration and try again.
400 | 43019 | exceed dept max level | The department hierarchy has reached 25 levels, and no more sub-departments can be created.
400 | 43021 | department chat not exist | Department group does not exist
400 | 43022 | department name duplicate | Department name is duplicated. You need to modify the passed name parameter value and try again.
400 | 43023 | dept structure no permissione | There is no department permission. The department needs to be within the address book permission scope of the application. For how to set the address book permission scope, see [Introduction to permission scope resources](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).
400 | 43024 | dept structure tenant lock fail | Failed to obtain tenant lock for department structure change. Conflict caused by concurrent requests, please try again later.
400 | 43025 | top department leader unjoined | The user has not joined and cannot become the department head. You need to change the department head to an active employee included in the contacts.
400 | 43026 | employee type is not valid | Invalid person type. You need to refer to the parameter description of group_chat_employee_types in the interface document to set the correct employee type.
400 | 43028 | invalid department hrbps | The department’s HRBP is illegal. When requesting, multiple user IDs for department HRBP can be set. You need to check whether the set user ID type is consistent with the type set by the query parameter user_id_type, and check whether the user ID value is correct. For how to obtain user ID, please refer to [How to obtain different user IDs](https://open.feishu.cn/document/home/user-identity-introduction/open-id).
400 | 43029 | dept name not contain separator | Department names cannot contain slashes (`/`).
400 | 43030 | update department lock error,wait some seconds and retry | Concurrency is limited, please try again later
400 | 43013 | dept too many children error | Too many sub-departments. The number of direct sub-departments of the department cannot exceed 1000.
400 | 43031 | Unable to edit data from external data sources | Unable to edit data from external data sources

For more error code information, see [General error codes](https://open.feishu.cn/document/ukTMukTMukTM/ugjM14COyUjL4ITN).

