Skip to main content

创建部门接口

在组织目录中新增部门,指定部门名称、上级部门和可选的外部标识。返回新部门的标识,供用户归属和后续部门维护使用。

  • Scope:admin.v1.user-directory.manage
  • 权限项:用户与部门管理(user-directory)
  • 权限类型:管理
  • 接口:POST/api/openapi/v1/departments

认证与请求头

使用应用 API Key 调用。当前接口只校验上方独立 Scope;读取、管理与执行权限互不隐含。
名称位置类型必填说明示例
Authorizationheaderstring是应用 API Key,使用 Bearer 方式传递。Bearer qwk_***
X-Request-Idheaderstring否可选的调用追踪标识;未传入时由服务端生成。req-20260831-001

请求参数

名称位置类型必填说明示例
Idempotency-Keyheaderstring必填幂等键,用于避免重复提交"<string>"
external_idbodystring否第三方部门 ID"<string>"
namebodystring必填部门名称"<string>"
parent_idbodystring | null · uuid否上级部门(部门 ID)"<uuid>"

请求示例

curl --request POST \
  --url 'https://example.invalid/api/openapi/v1/departments' \
  --header 'Authorization: Bearer <API_KEY>' \
  --header 'Idempotency-Key: <UNIQUE_REQUEST_ID>' \
  --header 'Content-Type: application/json' \
  --data '{
  "external_id": "<string>",
  "name": "<string>",
  "parent_id": "<uuid>"
}'

响应

201 Created

名称类型必填说明示例
department_idstring · uuid是部门 ID"<uuid>"
external_idstring否第三方部门 ID"<string>"
namestring是部门名称"<string>"
orderinteger · int64是排序0
parent_idstring | null是上级部门(部门 ID)"<string>"
{
  "department_id": "<uuid>",
  "external_id": "<string>",
  "name": "<string>",
  "order": 0,
  "parent_id": "<string>"
}

default Flat business error

名称类型必填说明示例
codestring否Stable business error code"<string>"
detailstring是Human-readable error description"<string>"
detailsOpenapiErrorDetails否错误详情-
errorstring是Stable HTTP error type"<string>"

details 字段

以下必填性针对对象存在时的子字段;父对象可否省略或为 null,以上层字段表为准。
字段类型必填说明
fieldstring否校验失败的请求字段
reasonstring否校验失败的原因代码
suggestionstring否建议使用的规范化值
{
  "code": "<string>",
  "detail": "<string>",
  "details": {
    "field": "<string>",
    "reason": "<string>",
    "suggestion": "<string>"
  },
  "error": "<string>"
}