更新部门
更新部门,支持数据行权限判权
Tip: - 停用部门时,请确认是否有与该部门关联的现任员工、变更文件、待入职。如果是这样,停用将失败。
- 如果启动/停止生效日期没有版本,将自动生成版本。
- 如果启动/停用生效日期存在版本,则该版本将被修改。
请求
| 项目 | 值 |
|---|---|
| HTTP URL | https://open.feishu.cn/open-apis/corehr/v2/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 示例值:"1616161616" |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
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: 【飞书】用来在具体某个应用中标识一个部门,同一个department_id 在不同应用中的 open_department_id 相同。 - department_id: 【飞书】用来标识租户内一个唯一的部门。 - people_corehr_department_id: 飞书人事】用来标识「飞书人事」中的部门。默认值: people_corehr_department_id |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | string | 否 | 该字段暂时无效,可忽略 示例值:"4719456877659520852" |
sub_type | enum | 否 | 部门类型,通过获取字段详情查询获取。请求参数:object_api_name=department;custom_api_name=subtype。 |
└ enum_name | string | 是 | 枚举值 示例值:"department" |
manager | string | 否 | 部门负责人 ID 详细信息可通过【搜索员工信息】 或 【批量查询员工】 接口获取 示例值:"6893013238632416776" |
is_confidential | boolean | 否 | 是否保密(该字段暂不支持,可忽略) 示例值:true |
hiberarchy_common | hiberarchy_common | 否 | 组织实体公共字段,包括名称、描述、上级、启停用状态、生效日期、编码等基础信息 |
└ parent_id | string | 否 | 上级组织 示例值:"4719168654814483759" |
└ name | i18n\[\] | 否 | 部门名称 - 名称不能包含「/」「;」「;」「\」「'」字符。 - 中英文名称会有重名校验规则(依赖租户配置规则) |
└ lang | string | 是 | 语言信息,中文用zh-CN,英文用en-US 示例值:"zh-CN" |
└ value | string | 是 | 文本内容 示例值:"中文示例" |
└ active | boolean | 否 | 部门启用状态,true为启用,false为停用 示例值:true |
└ code | string | 否 | 部门编码 (不能与其他记录的编码重复) 它的生效规则和 is_prefer_manual_encoding (是否优先使用手动编码)相关: - 当系统开启自动编码时: 若 is_prefer_manual_encoding=true:传入的 code 会生效,不传则自动生成编码。 若 is_prefer_manual_encoding=false:传的 code 会被忽略,以系统自动生成的编码为准。 - 当系统未开启自动编码时:无论 is_prefer_manual_encoding取值如何,均以传入的 code 为准。 示例值:"12456" |
└ description | i18n\[\] | 否 | 描述 |
└ lang | string | 是 | 语言信息,中文用zh-CN,英文用en-US 示例值:"zh-CN" |
└ value | string | 是 | 文本内容 示例值:"中文示例" |
effective_time | string | 是 | 版本生效日期 - 填写格式:YYYY-MM-DD 00:00:00(系统会自动将时分秒改为00:00:00) - 系统默认为填写日期当天的 00:00:00 生效 - 该接口只支持到最小单位为日 - 日期范围要求:1900-01-01 00:00:00~9999-12-31 23:59:59 示例值:"2020-05-01 00:00:00" |
custom_fields | object_field_data\[\] | 否 | 自定义字段,枚举值可通过获取自定义字段列表获取 数据校验规则: - 长度范围: 0 ~ 100 |
└ field_name | string | 是 | 自定义字段 apiname,即自定义字段的唯一标识 示例值:"name" |
└ value | string | 是 | 字段值,为 JSON 转义后的字符串。 注意:具体传值方式参见获取自定义字段的元数据 示例值:"Sandy" |
cost_center_id | string | 否 | 成本中心 ID,可以通过搜索成本中心信息接口获取对应的成本中心信息 示例值:"7142384817131652652" |
staffing_model | enum | 否 | 岗职管理模式 - 详细枚举类型请查看枚举场景中关于staffing_model定义 |
└ enum_name | string | 是 | 枚举值:job、position、non_job 示例值:"job" |
is_prefer_manual_encoding | boolean | 否 | 是否优先使用手动编码 - 设为 true:优先使用传入的 code。即使系统开启了自动编码,只要传了 code,以传入值为准; 未传code时,会回退到自动生成编码。 - 设为 false:遵循系统默认策略。此时若系统开启了自动编码,传入的 code 不会生效,以系统自动生成的编码为准 示例值:false |
请求体示例
json
{
"id": "4719456877659520852",
"sub_type": {
"enum_name": "department"
},
"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"
},
"is_prefer_manual_encoding": false
}响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
code | int | 错误码,非 0 表示失败 |
msg | string | 错误描述 |
data | \- | - |
响应体示例
json
{
"code": 0,
"msg": "success",
"data": {}
}错误码
| HTTP状态码 | 错误码 | 描述 | 排查建议 |
|---|---|---|---|
| 400 | 1160004 | client_token repeat. | 重复请求,请确认是否已处理完成 |
| 500 | 1160101 | marshal error | marshal error |
| 500 | 1160102 | unmarshal error | unmarshal error |
| 500 | 1160103 | request ID repeat | 重复请求,请确认是否已处理完成 |
| 500 | 1160104 | custom field format error | 请检查自定义字段的格式是否正确 |
| 500 | 1160105 | field is required | 上级部门为必填,请检查上级部门是否为空 |
| 500 | 1160106 | date format should be 2006-01-02 | 请检查时间类型字段的格式是否正确 |
| 400 | 1160107 | param is invalid | 请检查参数是否正确 |
| 400 | 1160258 | manager hasn't been onboard on effective date | 请检查人员在生效日期下是否未入职 |
| 400 | 1160259 | manager offboarded on effective date | 请检查人员在生效日期下是是否已离职 |
| 400 | 1160269 | effective date can't exceed 9999 | 生效日期不允许大于 9999 年,请检查生效日期是否正确 |
| 400 | 1160321 | enter an array for field | 请检查字段是否正确 |
| 400 | 1160327 | metadata of field doesn't exist | 请检查字段是否正确 |
| 400 | 1160328 | Enter an integer for field | 请检查传参是否正确 |
| 400 | 1160329 | field exceeds the maximum value | 请检查数字大小是否在范围内 |
| 400 | 1160330 | field exceeds the minimum value | 请检查数字大小是否在范围内 |
| 400 | 1160331 | Enter an integer or decimal for field | 请检查数字格式是否正确 |
| 400 | 1160332 | enter a boolean value for field | 请检查传参是否正确 |
| 400 | 1160333 | Enter an i18n object for field | 请检查多语字段传参是否正确 |
| 400 | 1160334 | Enter an enumeration value for field | 请检查传参是否正确 |
| 400 | 1160335 | Enter an array for field | 请检查传参是否正确 |
| 400 | 1160336 | org doesn't exist | 请检查 org 是否存在 |
| 400 | 1160338 | field must be a string | 请检查传参是否正确 |
| 400 | 1160339 | field must be a string | 请检查传参是否正确 |
| 400 | 1160340 | field must be in the yyyy-MM-dd HH:mm:ss format | 请检查时间格式是否正确 |
| 400 | 1160342 | reason is required | 请检查传参是否正确 |
| 400 | 1160343 | Duplicate code | 请检查编码是否与其他记录重复 |
| 400 | 1160344 | unable to edit org as it was deactivated on date | 请检查停启用状态 |
| 400 | 1160347 | org will be deactivated | 请检查停启用状态 |
| 400 | 1160349 | org deactivated on date | 请检查停启用状态 |
| 400 | 1160352 | The option has been deactivated | 请检查枚举类字段的选项是否已停用 |
| 400 | 1160353 | effective date can't be earlier than 1900 | 生效日期不能早于 1900 年 |
| 400 | 1160354 | service rate limiting protection, please try again later | 请稍后再试 |
