> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trae.cn/llms.txt
> Use this file to discover all available pages before exploring further.

在指定父部门下创建一个子部门。

需要一次创建多个相互独立的部门时，使用 “批量创建部门” 接口。

## 所需权限 {#hKuboqrPx}

`departments:write`

## 请求说明 {#hhMEQKcdJ}

* 请求方式：`POST`
* 请求地址：`{域名}/openapi/v1/departments`

## 相关限制 {#hkROrqDem}


* 单次请求仅支持创建一个子部门。
* 部门树最大深度为 11 级（含根部门）。
* 企业部门总数上限为 10000。

## 请求参数 {#hofB9iyd2}

### 请求头参数 {#hKRYkhajZ}

<!-- @cols-width: 172,122,596 -->
| **Header 参数**  | **是否必填**  | **描述**  |
| --- | --- | --- |
| `Authorization`  | 是  | 固定取值为 `Bearer {access_token}`。关于如何获取访问令牌，参考[鉴权](enterprise_authentication)。  |
| `Content-Type`  | 是  | 固定取值为 `application/json`。  |

### 请求体参数 {#hHmIB2OPA}

<!-- @cols-width: 183,100,100,100,408 -->
| **参数**  | **类型**  | **是否必填**  | **默认值**  | **描述**  |
| --- | --- | --- | --- | --- |
| `parent_department_id`  | string  | 否  | \-  | 父部门的 ID。 | \
| | | | | | \
| | | | | 省略、传 `"0"` 或空字符串表示直接在企业根部门下创建新部门。 | \
| | | | | | \
| | | | | 部门 ID 可以通过 “[获取单个父部门的子部门](/enterprise_get-the-subdepartments-for-a-specified-parent-department)” 接口或 ”[按关键词搜索部门](/enterprise_query-department-by-keyword)“ 接口获取。  |
| `name`  | string  | 是  | \-  | 子部门名称。 | \
| | | | | | \
| | | | | 去除首尾空白后非空，最多 30 个 Unicode 字符；同一父部门下名称不能重复。  |

## 响应参数 {#响应参数}

该接口独有的响应参数如下，参数位于 `data` 中。通用响应参数参考[此文档](/enterprise_general-response-schema)。

<!-- @cols-width: 222,244,417 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `department_id`  | string  | 新创建的部门的 ID。  |

## 示例 {#示例}

### 请求示例 {#请求示例}

```Bash
curl -X POST "${HOST}/openapi/v1/departments" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "parent_department_id": "10001",
    "name": "AI 组"
  }'
```

### 响应示例 {#响应示例}

```JSON
{
  "code": 0,
  "message": "success",
  "request_id": "req_xxx",
  "data": {
    "department_id": "10002"
  }
}
```

## 错误码 {#错误码}

若该接口的请求返回错误码，参考[错误码](/enterprise_error-codes)文档进行排查。
