> ## 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.

# Delete a department

> Call this API to delete a specified department by its department ID, ensuring that the department has no sub-departments or members before deletion.

Call this API to delete a specified department by its department ID.

## API call description

A department cannot be deleted in the following cases:

* The root department (department ID 1) cannot be deleted.
* The department or its sub-departments still contain employees that have not been deleted.

## Request

| **Basic information** |                                                                                                            |
| --------------------- | ---------------------------------------------------------------------------------------------------------- |
| HTTP URL              | [https://api.dingtalk.io/topapi/v2/department/delete](https://api.dingtalk.io/topapi/v2/department/delete) |
| HTTP Method           | POST                                                                                                       |
| Supported app type    | appType-Internal app                                                                                       |
| Required permissions  | permission-qyapi\_manage\_addresslist-Contacts data management permission                                  |

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                    |
| ------------- | ------ | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | bE74xxxx | The app credential used to call this API. Obtain it through the API for getting the [access\_token of an internal app](/open/development/obtain-orgapp-token). |

### Request body

| Name     | Type   | Required | Example | Description                                                                                                                                                                   |
| -------- | ------ | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| dept\_id | Number | Yes      | 100     | The ID of the department to delete. You can obtain the dept\_id value through the [Get department list](/open/development/user-management-acquires-the-list-departments) API. |

### Request example

```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);
```

## Response

### Response body

| Name        | Type   | Example      | Description                         |
| ----------- | ------ | ------------ | ----------------------------------- |
| errcode     | Number | 0            | The return code.                    |
| errmsg      | String | ok           | The description of the return code. |
| request\_id | String | 6iq4zcul5zjp | The request ID.                     |

### Response example

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

### Error codes

If an error is returned when you call this API, look up the solution by the error message in the [Global error codes](/open/development/server-api-error-codes-1) document.

| Error code (errcode) | Error message (errmsg) | Solution                                                     |
| -------------------- | ---------------------- | ------------------------------------------------------------ |
| 43007                | Authorization required | Confirm that the access\_token has the required permissions. |
| 60003                | Department not found   | Confirm that the dept\_id is correct.                        |
| 400002               | Invalid parameter      | Confirm that the parameters are entered as required.         |
| -1                   | System busy            | Try again later.                                             |
