Skip to content

批量新增部门

该接口用于向通讯录中批量新增多个部门。

Warning: 调用该接口需要具有所有新增部门父部门的授权范围。 应用商店应用无权限调用此接口。 调用该接口需要申请 更新通讯录 以及 以应用身份访问通讯录 权限。

请求

项目
HTTP URLhttps://open.feishu.cn/open-apis/contact/v2/department/batch_add
HTTP MethodPOST
权限要求 调用该 API 所需的权限。开启其中任意一项权限即可调用 开启任一权限即可更新通讯录 以应用身份访问通讯录(历史版本)

请求头

名称类型必填描述
Authorizationstringtenant_access_token 值格式:"Bearer access_token" 示例值:"Bearer t-7f1bcd13fc57d46bac21793a18e560" 了解更多:如何选择与获取 access token
Content-Typestring固定值:"application/json; charset=utf-8"

请求体

参数类型必填 / 选填说明
departmentsarray必填所有要新增部门的集合。
 ∟idstring选填自定义部门 ID,企业内必须唯一。只能在创建部门时指定,不支持更新。
若不填该参数,将自动生成。
不区分大小写,长度为 1 ~ 64 个字符。只能由数字、字母和“_”、“-”、“@”、“.”四种特殊字符组成,且第一个字符必须是数字或字母。
 ∟namestring必填部门名称。
 ∟parent_idstring必填父部门 ID。
当被添加的部门为企业一级部门时,此字段填写“0”。
 ∟leader_user_id
 ∟leader_open_id
string选填部门负责人 ID,支持通过 user_id 或 open_id 进行设置。
请求同时传递两个字段时只使用 leader_user_id,忽略 leader_open_id。
 ∟create_group_chatbool选填是否同时创建部门群,默认为 false,不创建部门群。

请求体示例

json
{
    "departments": [
        {
            "id": "custom_1",
            "name": "custom_1",
            "parent_id": "custom_2",
            "leader_user_id": "id_zhangsan",
            "leader_open_id": "ou_123456787999b8329abcdef00f7ce93c",
            "create_group_chat": true
        },
        {
            "id": "custom_2",
            "name": "custom_2",
            "parent_id": "0"
        }
    ]
}

响应

响应体

参数说明
code返回码,非 0 表示失败。
msg对返回码的文本描述。
data-
 ∟task_id生成的异步任务 ID,参见 查询批量任务执行状态 接口。

响应体示例

json
{
    "code": 0,
    "msg": "success",
    "data": {
        "task_id": "123456784b68a7c89abcdef092dc09ea"
    }
}

错误码

具体可参考:服务端错误码说明

内容来源:飞书开放平台 · 自动爬取整理