更新部门
更新部门信息,包括基础信息、自定义字段信息。
Error: 该接口不再推荐使用,请使用【更新部门】接口。
Warning: 权限说明:该接口不支持范围权限校验,不支持字段权限校验
请求
| 项目 | 值 |
|---|---|
| HTTP URL | https://open.feishu.cn/open-apis/corehr/v1/departments/:department_id |
| HTTP Method | PATCH |
| 接口频率限制 | 100 次/分钟 |
| 支持的应用类型 | custom |
| 权限要求 调用该 API 所需的权限。开启其中任意一项权限即可调用 开启任一权限即可 | corehr:corehr 更新核心人事信息 corehr:department:write 读写部门信息 |
| 字段权限要求 | > Tip: 该接口返回体中存在下列敏感字段,仅当开启对应的权限后才会返回;如果无需获取这些字段,则不建议申请 contact:user.employee_id:readonly 获取用户 user ID |
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | string | 是 | tenant_access_token 值格式:"Bearer access_token" 示例值:"Bearer t-7f1bcd13fc57d46bac21793a18e560" 了解更多:如何选择与获取 access token |
| Content-Type | string | 是 | 固定值:"application/json; charset=utf-8" |
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
department_id | string | 需要更新的部门ID,同部门实体在CoreHR内部的唯一键 示例值:"6969828847121885087" |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
client_token | string | 否 | 根据client_token是否一致来判断是否为同一请求 示例值:12454646 |
user_id_type | string | 否 | 用户 ID 类型 示例值:people_corehr_id 可选值有: - open_id: 标识一个用户在某个应用中的身份。同一个用户在不同应用中的 Open ID 不同。了解更多:如何获取 Open ID - union_id: 标识一个用户在某个应用开发商下的身份。同一用户在同一开发商下的应用中的 Union ID 是相同的,在不同开发商下的应用中的 Union ID 是不同的。通过 Union ID,应用开发商可以把同个用户在多个应用中的身份关联起来。了解更多:如何获取 Union ID? - user_id: 标识一个用户在某个租户内的身份。同一个用户在租户 A 和租户 B 内的 User ID 是不同的。在同一个租户内,一个用户的 User ID 在所有应用(包括商店应用)中都保持一致。User ID 主要用于在不同的应用间打通用户数据。了解更多:如何获取 User ID? - people_corehr_id: 以飞书人事的 ID 来识别用户默认值: people_corehr_id当值为 user_id,字段权限要求: contact:user.employee_id:readonly 获取用户 user ID |
department_id_type | string | 否 | 此次调用中使用的部门 ID 类型 示例值:people_corehr_department_id 可选值有: - open_department_id: 以 open_department_id 来标识部门 - department_id: 以 department_id 来标识部门 - people_corehr_department_id: 以 people_corehr_department_id 来标识部门默认值: people_corehr_department_id |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | string | 否 | 部门 ID 示例值:"6969828847121885087" |
sub_type | enum | 否 | 部门子类型,枚举值可通过文档【飞书人事枚举常量】部门子类型(department_sub_type)枚举定义部分获得 |
└ enum_name | string | 是 | 枚举值 示例值:"type_1" |
manager | string | 否 | 部门负责人 ID,枚举值及详细信息可通过【批量查询员工信息】查询获得 示例值:"6893013238632416776" |
is_confidential | boolean | 否 | 是否保密 示例值:true |
hiberarchy_common | hiberarchy_common | 否 | 组织实体公共字段,包括名称、描述、上级、启停用状态、生效日期、编码等基础信息 |
└ parent_id | string | 否 | 上级组织 ID 示例值:"4719168654814483759" |
└ name | i18n\[\] | 否 | 名称 |
└ lang | string | 是 | 名称信息的语言,支持中文和英文。中文用zh-CN;英文用en-US。 示例值:"zh-CN" |
└ value | string | 是 | 名称信息的内容 示例值:"研发部" |
└ active | boolean | 否 | 是否启用该部门 示例值:true |
└ code | string | 否 | 编码 示例值:"12456" |
└ description | i18n\[\] | 否 | 描述 |
└ lang | string | 是 | 名称信息的语言,支持中文和英文。中文用zh-CN;英文用en-US。 示例值:"zh-CN" |
└ value | string | 是 | 名称信息的内容 示例值:"张三" |
effective_time | string | 是 | 生效时间 示例值:"2020-05-01 00:00:00" |
custom_fields | object_field_data\[\] | 否 | 自定义字段,枚举值可通过获取自定义字段列表获取 |
└ field_name | string | 是 | 自定义字段 apiname,即自定义字段的唯一标识 示例值:"name" |
└ value | string | 是 | 字段值,是json转义后的字符串,根据元数据定义不同,字段格式不同(如123, 123.23, "true", ["id1","id2"], "2006-01-02 15:04:05") 示例值:""Sandy"" |
cost_center_id | string | 否 | 成本中心 ID,可以通过搜索成本中心信息接口获取对应的成本中心信息 示例值:"7142384817131652652" |
staffing_model | enum | 否 | 岗职管理模式 - 详细枚举类型请查看枚举场景中关于staffing_model定义 |
└ enum_name | string | 是 | 枚举值 示例值:"job" |
请求体示例
json
{
"id": "6969828847121885087",
"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"
}
}响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
code | int | 错误码,非 0 表示失败 |
msg | string | 错误描述 |
data | \- | - |
└ department | department | 部门 |
└ id | string | 部门 ID |
└ sub_type | enum | 部门子类型,枚举值可通过文档【飞书人事枚举常量】部门子类型(department_sub_type)枚举定义部分获得 |
└ enum_name | string | 枚举值 |
└ display | i18n\[\] | 枚举多语展示 |
└ lang | string | 名称信息的语言,支持中文和英文。中文用zh-CN;英文用en-US。 |
└ value | string | 名称信息的内容 |
└ manager | string | 部门负责人 ID,枚举值及详细信息可通过【批量查询员工信息】查询获得 |
└ is_confidential | boolean | 是否保密 |
└ hiberarchy_common | hiberarchy_common | 组织实体公共字段,包括名称、描述、上级、启停用状态、生效日期、编码等基础信息 |
└ parent_id | string | 上级组织 ID |
└ name | i18n\[\] | 名称 |
└ lang | string | 名称信息的语言,支持中文和英文。中文用zh-CN;英文用en-US。 |
└ value | string | 名称信息的内容 |
└ type | enum | 组织类型,枚举值可通过文档【飞书人事枚举常量】组织类型(organization_type)枚举定义部分获得 |
└ enum_name | string | 枚举值 |
└ display | i18n\[\] | 枚举多语展示 |
└ lang | string | 名称信息的语言,支持中文和英文。中文用zh-CN;英文用en-US。 |
└ value | string | 名称信息的内容 |
└ active | boolean | 是否启用 |
└ effective_time | string | 生效时间 |
└ expiration_time | string | 失效时间 |
└ code | string | 编码 |
└ description | i18n\[\] | 描述 |
└ lang | string | 名称信息的语言,支持中文和英文。中文用zh-CN;英文用en-US。 |
└ value | string | 名称信息的内容 |
└ tree_order | string | 树形排序,代表同层级的部门排序序号。新建的部门,该字段默认为空,有两种情况会自动写入值: - 管理员在部门管理页面上拖动排序; - 定时任务更新该字段为空的数据,3分钟/次 |
└ list_order | string | 列表排序,代表所有部门的混排序号。新建的部门,该字段默认为空,有两种情况会自动写入值: - 管理员在部门管理页面上拖动排序; - 定时任务更新该字段为空的数据,3分钟/次 |
└ custom_fields | object_field_data\[\] | 自定义字段 |
└ field_name | string | 自定义字段 apiname,即自定义字段的唯一标识,枚举值可通过获取自定义字段列表接口查询 |
└ value | string | 字段值,是json转义后的字符串,根据元数据定义不同,字段格式不同(如123, 123.23, "true", ["id1","id2"], "2006-01-02 15:04:05") |
└ effective_time | string | 生效时间 |
└ expiration_time | string | 失效时间 |
└ custom_fields | object_field_data\[\] | 自定义字段 |
└ field_name | string | 字段名 |
└ value | string | 字段值,是json转义后的字符串,根据元数据定义不同,字段格式不同(如123, 123.23, "true", ["id1","id2"], "2006-01-02 15:04:05") |
└ cost_center_id | string | 成本中心 ID,可以通过搜索成本中心信息接口获取对应的成本中心信息 |
└ staffing_model | enum | 岗职务模式 |
└ enum_name | string | 枚举值:job、non_job、position |
└ display | i18n\[\] | 枚举多语展示 |
└ lang | string | 语言,支持中文和英文。中文用zh-CN;英文用en-US。 |
└ value | string | 内容 |
响应体示例
json
{
"code": 0,
"msg": "success",
"data": {
"department": {
"id": "6969828847121885087",
"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": "job",
"display": [
{
"lang": "zh-CN",
"value": "刘梓新"
}
]
}
}
}
}错误码
| HTTP状态码 | 错误码 | 描述 | 排查建议 |
|---|---|---|---|
| 500 | 1160101 | marshal error | 已废弃 |
| 500 | 1160102 | unmarshal error | 已废弃 |
| 500 | 1160103 | request ID is required | 请检查 ID 是否为空 |
| 500 | 1160104 | custom field format error | 请检查自定义字段的格式是否正确 |
| 500 | 1160105 | field is required | 已废弃 |
| 500 | 1160106 | date format should be YYYY-MM-DD hh:mm:ss | 请检查时间类型字段的格式是否正确 |
| 400 | 1160107 | param is invalid | 已废弃 |
| 400 | 1160251 | superior department is required | 上级部门为必填,请检查上级部门是否为空 |
| 400 | 1160252 | the number of characters in the text field exceeds the limit | 文本类字段的长度超过限制,请减少字符数 |
| 400 | 1160253 | the name can't contain "/", ";", or ";" | 部门名称中包含「/」、「;」、「;」,请删除相关特殊字符 |
| 400 | 1160254 | name already exists | 请检查名称是否与其他记录重复 |
| 400 | 1160258 | the individual hasn't been onboard on effective date | 请检查人员在生效日期下是否未入职 |
| 400 | 1160259 | the individual offboarded on effective date | 请检查人员在生效日期下是是否已离职 |
| 400 | 1160263 | code already exists | 请检查编码是否与其他记录重复 |
| 400 | 1160264 | this operation will make the relationship between the superior and the subordinate into a ring | 部门上下级关系成环,请检查上级部门是否正确 |
| 400 | 1160269 | effective date can't exceed 9999 | 生效日期不允许大于 9999 年,请检查生效日期是否正确 |
| 400 | 1160321 | the name already exists | 名称已存在,请使用其他名称 |
| 400 | 1160327 | the field doesn't exist | 请检查字段是否正确 |
| 400 | 1160343 | Duplicate code | 已废弃 |
| 400 | 1160344 | unable to edit org as it was deactivated on date | 已废弃 |
| 400 | 1160347 | superior department will be deactivated on or after the effective date | 上级部门在生效日期或之后将停用,请检查上级部门是否准确 |
| 400 | 1160349 | superior department will be deactivated on or after the effective date | 上级部门在生效日期或之后将停用,请检查上级部门是否准确 |
| 400 | 1160352 | the option has been deactivated | 请检查枚举类字段的选项是否已停用 |
| 400 | 1160353 | the effective date can't be earlier than 1900 | 生效日期不能早于 1900 年 |
| 400 | 1160354 | service rate limiting protection, please try again later | 已废弃 |
