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

# 删除部门

> 调用本接口可根据部门 ID 删除指定部门,删除前需确保该部门下无子部门与成员。

调用本接口根据部门ID删除指定部门。

## 接口调用说明

以下情况无法删除部门：

* 不能删除根部门，即部门ID为1。
* 部门或子部门内还有未删除的员工。

## 请求

| **基本信息**    |                                                                                                            |
| ----------- | ---------------------------------------------------------------------------------------------------------- |
| HTTP URL    | [https://api.dingtalk.io/topapi/v2/department/delete](https://api.dingtalk.io/topapi/v2/department/delete) |
| HTTP Method | POST                                                                                                       |
| 支持的应用类型     | appType-企业内部应用                                                                                             |
| 权限要求        | permission-qyapi\_manage\_addresslist-通讯录数据管理权限                                                            |

### 查询参数

| 名称            | 类型     | 是否必填 | 示例值      | 描述                                                                                   |
| ------------- | ------ | ---- | -------- | ------------------------------------------------------------------------------------ |
| access\_token | String | 是    | bE74xxxx | 调用该接口的应用凭证，通过[获取企业内部应用的access\_token](/zh/open/development/obtain-orgapp-token)接口获取。 |

### 请求体

| 名称       | 类型     | 是否必填 | 示例值 | 描述                                                                                                       |
| -------- | ------ | ---- | --- | -------------------------------------------------------------------------------------------------------- |
| dept\_id | Number | 是    | 100 | 要删除的部门ID，可通过[获取部门列表](/zh/open/development/user-management-acquires-the-list-departments)接口获取dept\_id参数值。 |

### 请求示例

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/department/delete" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=f11exxxx6c373a925b' \
-d 'dept_id=100'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/delete");
OapiV2DepartmentDeleteRequest req = new OapiV2DepartmentDeleteRequest();
req.setDeptId(100L);
OapiV2DepartmentDeleteResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

req=dingtalk.api.OapiV2DepartmentDeleteRequest("https://api.dingtalk.io/topapi/v2/department/delete")

req.dept_id=100
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiV2DepartmentDeleteRequest;
$req->setDeptId("100");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/department/delete");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/delete");
OapiV2DepartmentDeleteRequest req = new OapiV2DepartmentDeleteRequest();
req.DeptId = 100L;
OapiV2DepartmentDeleteResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## 响应

### 响应体

| 名称          | 类型     | 示例值          | 描述     |
| ----------- | ------ | ------------ | ------ |
| errcode     | Number | 0            | 返回码。   |
| errmsg      | String | ok           | 返回码描述。 |
| request\_id | String | 6iq4zcul5zjp | 请求ID。  |

### 响应体示例

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
 "errcode":0,
 "errmsg": "ok",
 "request_id": "6iq4zcul5zjp"
}
```

### 错误码

若调用该接口报错，可根据错误信息在[全局错误码](/zh/open/development/server-api-error-codes-1)文档中查找解决方案。

| 错误码（errcode） | 错误码描述（errmsg） | 解决方案                   |
| ------------ | ------------- | ---------------------- |
| 43007        | 需要授权          | 请确认access\_token具有操作权限 |
| 60003        | 未找到对应部门       | 请确认dept\_id是否正确        |
| 400002       | 无效的参数         | 请确认参数是否按要求输入           |
| -1           | 系统繁忙          | 请稍后再试                  |
