# update department

Update department information, including basic information and custom field information.
**Notice**：This interface is no longer recommended, please use the [[Update Department]](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/corehr-v2/department/patch) interface.
**Notice**：Permission description: This API does not support scope permission verification, and does not support field permission verification.

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/corehr/v1/departments/:department_id
HTTP Method | PATCH
Rate Limit | [100 per minute](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.**<br>Enable any scope from the list | Update core HR information(corehr:corehr)<br>Update department information(corehr:department:write)
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 user ID(contact:user.employee_id:readonly)

### 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 to be updated<br>**Example value**: "1616161616"

### Query parameters

Parameter | Type | Required | Description
---|---|---|---
client_token | string | No | Determine whether it is the same request according to whether the client_token are consistent<br>**Example value**: 12454646
user_id_type | string | No | User ID categories<br>**Example value**: people_corehr_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>- people_corehr_id：Identify users with Feishu personnel IDs<br>**Default value**: `people_corehr_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 department ID type used in this call<br>**Example value**: people_corehr_department_id<br>**Optional values are**:<br>- open_department_id：Identify departments open_department_id<br>- department_id：Identify departments department_id<br>- people_corehr_department_id：Identify departments people_corehr_department_id<br>**Default value**: `people_corehr_department_id`

### Request body

Parameter | Type | Required | Description
---|---|---|---
id | string | No | Entity's unique key inside CoreHR<br>**Example value**: "4719456877659520852"
sub_type | enum | No | Subtype
enum_name | string | Yes | Enumeration value<br>**Example value**: "type_1"
manager | string | No | Head of Department<br>**Example value**: "6893013238632416776"
is_confidential | boolean | No | Is it confidential<br>**Example value**: true
hiberarchy_common | hiberarchy_common | No | Hierarchical relationship, see entity for inner field
parent_id | string | No | Higher organization, this field is a general field. If it is the department dimension, it is required.<br>**Example value**: "4719168654814483759"
name | i18n\[\] | No | Name
lang | string | Yes | Language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.<br>**Example value**: "zh-CN"
value | string | Yes | Content<br>**Example value**: "研发部"
active | boolean | No | Enable the department<br>**Example value**: true
code | string | No | Encoding<br>**Example value**: "12456"
description | i18n\[\] | No | Description
lang | string | Yes | Language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.<br>**Example value**: "zh-CN"
value | string | Yes | Content<br>**Example value**: "张三"
effective_time | string | Yes | Effective time<br>**Example value**: "2020-05-01 00:00:00"
custom_fields | object_field_data\[\] | No | Custom fields
field_name | string | Yes | Field name<br>**Example value**: "name"
value | string | Yes | The field value is the character string after json escape. According to the metadata definition, the field format is different (such as 123, 123.23, "true", [\ "id1\",\ "id2 \"], " 2006-01-02 15:04:05")<br>**Example value**: "Sandy"
cost_center_id | string | No | Cost center ID, you can get the corresponding cost center information through the [Search cost center information](https://open.feishu.cn/document/server-docs/corehr-v1/organization-management/cost_center/search) interface<br>**Example value**: "7142384817131652652"
staffing_model | enum | No | Post management mode<br>- For detailed enumeration types, please refer to the definition of staffing_model in [enumeration scene](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/corehr-v1/feishu-people-enum-constant)
enum_name | string | Yes | enumeration value<br>**Example value**: "job"

### Request body example
```json
{
    "id": "4719456877659520852",
    "sub_type": {
        "enum_name": "type_1"
    },
    "manager": "6893013238632416776",
    "is_confidential": true,
    "hiberarchy_common": {
        "parent_id": "4719168654814483759",
        "name": [
            {
                "lang": "zh-CN",
                "value": "研发部"
            }
        ],
        "active": true,
        "code": "12456",
        "description": [
            {
                "lang": "zh-CN",
                "value": "张三"
            }
        ]
    },
    "effective_time": "2020-05-01 00:00:00",
    "custom_fields": [
        {
            "field_name": "name",
            "value": "Sandy"
        }
    ],
    "cost_center_id": "7142384817131652652",
    "staffing_model": {
        "enum_name": "job"
    }
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
department | department | Department
id | string | Entity's unique key inside CoreHR
sub_type | enum | Subtype
enum_name | string | Enumeration value
display | i18n\[\] | Enumeration multilingual display
lang | string | Language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.
value | string | Content
manager | string | Head of Department
is_confidential | boolean | Is it confidential
hiberarchy_common | hiberarchy_common | Hierarchical relationship, see entity for inner field
parent_id | string | Higher organization, this field is a general field. If it is the department dimension, it is required.
name | i18n\[\] | Name
lang | string | Language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.
value | string | Content
type | enum | Organization type
enum_name | string | Enumeration value
display | i18n\[\] | Enumeration multilingual display
lang | string | Language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.
value | string | Content
active | boolean | Enable
effective_time | string | Effective time
expiration_time | string | Failure time
code | string | Encoding
description | i18n\[\] | Description
lang | string | Language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.
value | string | Content
tree_order | string | Tree sorting, representing the sorting sequence number of departments at the same level. For newly created departments, this field is empty by default, and the value will be automatically written in two cases:<br>- Administrators drag and sort on the department management page;<br>- Scheduled tasks update data with this field empty, 3 minutes/time
list_order | string | List sort, representing the mixed sort number of all departments. For newly created departments, this field defaults to empty, and the value is automatically written in two cases:<br>- Administrators drag and sort on the department management page;<br>- Scheduled tasks update data with this field empty, 3 minutes/time
custom_fields | object_field_data\[\] | Custom fields
field_name | string | Field name
value | string | The field value is the character string after json escape. According to the metadata definition, the field format is different (such as 123, 123.23, "true", [\ "id1\",\ "id2 \"], " 2006-01-02 15:04:05")
effective_time | string | Effective time
expiration_time | string | Failure time
custom_fields | object_field_data\[\] | Custom fields
field_name | string | Field name
value | string | The field value is the character string after json escape. According to the metadata definition, the field format is different (such as 123, 123.23, "true", [\ "id1\",\ "id2 \"], " 2006-01-02 15:04:05")
cost_center_id | string | Cost center id
staffing_model | enum | Whether to use the position
enum_name | string | enumeration value
display | i18n\[\] | enumeration multilingual presentation
lang | string | language.Support Chinese and English. Use zh-CN for Chinese and en-US for English.
value | string | content

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "department": {
            "id": "4719456877659520852",
            "sub_type": {
                "enum_name": "type_1",
                "display": [
                    {
                        "lang": "zh-CN",
                        "value": "张三"
                    }
                ]
            },
            "manager": "6893013238632416776",
            "is_confidential": true,
            "hiberarchy_common": {
                "parent_id": "4719168654814483759",
                "name": [
                    {
                        "lang": "zh-CN",
                        "value": "张三"
                    }
                ],
                "type": {
                    "enum_name": "type_1",
                    "display": [
                        {
                            "lang": "zh-CN",
                            "value": "张三"
                        }
                    ]
                },
                "active": true,
                "effective_time": "2020-05-01 00:00:00",
                "expiration_time": "2020-05-02 00:00:00",
                "code": "12456",
                "description": [
                    {
                        "lang": "zh-CN",
                        "value": "张三"
                    }
                ],
                "tree_order": "001000",
                "list_order": "001000-001000",
                "custom_fields": [
                    {
                        "field_name": "name",
                        "value": "Sandy"
                    }
                ]
            },
            "effective_time": "2020-05-01 00:00:00",
            "expiration_time": "2020-05-02 00:00:00",
            "custom_fields": [
                {
                    "field_name": "name",
                    "value": "Sandy"
                }
            ],
            "cost_center_id": "7142384817131652652",
            "staffing_model": {
                "enum_name": "phone_type",
                "display": [
                    {
                        "lang": "zh-CN",
                        "value": "刘梓新"
                    }
                ]
            }
        }
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
500 | 1160101 | Marshal error | Abandoned
500 | 1160102 | Unmarshal error | Abandoned
500 | 1160103 | Request ID is required | Please check if the ID is empty.
500 | 1160104 | Custom field format error | Please check if the format of the custom field is correct.
500 | 1160105 | Field is required | Abandoned
500 | 1160106 | Date format should be YYYY-MM-DD hh: mm: ss | Please check that the format of the time type field is correct
400 | 1160107 | Param is invalid | Abandoned
400 | 1160251 | Superior department is required | The superior department is required, please check whether the superior department is empty.
400 | 1160252 | Superior department is required | The length of the text class field exceeds the limit, please reduce the number of characters
400 | 1160253 | The name can't con t ain "/", "；", or ";" | Department name contains 「/」、「；」、「;」， Please remove relevant special characters
400 | 1160254 | name already exists | Department name contains 「/」、「；」、「;」， Please remove relevant special characters
400 | 1160258 | The individual hasn't been onboard on effective date | Please check whether the personnel have not been hired under the effective date
400 | 1160259 | The individual offboarded on effective date | Please check whether the staff has left the company under the effective date
400 | 1160263 | Code already exists | Please check if the encoding is duplicated with other records
400 | 1160264 | This operation will make the relationship between the superior and the subordinate into a ring | The relationship between superiors and subordinates in the department is formed into a ring, please check whether the superior department is correct.
400 | 1160269 | Effective date can 't exceed 9999 | The effective date is not allowed to be greater than 9999 years. Please check if the effective date is correct.
400 | 1160321 | The name already exists | The name already exists, please use another name
400 | 1160327 | The field doesn 't exist | Please check if the field is correct.
400 | 1160343 | Duplicate code | Abandoned
400 | 1160344 | Unable to edit org as it was deactivated on date | Abandoned
400 | 1160347 | Superior department will be deactivated on or after the effective date | The superior department will be deactivated on or after the effective date, please check whether the superior department is accurate.
400 | 1160349 | Superior {department}} will be deactivated on or after the effective date | The superior department will be deactivated on or after the effective date, please check whether the superior department is accurate.
400 | 1160352 | The option has been deactivated | Please check whether the option to enumerate class fields is disabled
400 | 1160353 | The effective date can 't be earlier than 1900 | The effective date cannot be earlier than 1900
400 | 1160354 | Service rate limiting protection, please try again later | Abandoned

