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

# 部門の削除

> 企業内の部門を削除して、組織構造を管理できます

本 API を呼び出して、部門 ID を指定して該当部門を削除します。

## API 呼び出し説明

以下の場合は部門を削除できません。

* ルート部門（部門 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 | 当該 API を呼び出すためのアプリ認証情報。[社内アプリの access\_token を取得する](/ja/open/development/obtain-orgapp-token) API で取得します。 |

### リクエストボディ

| 名前       | タイプ    | 必須 | 例   | 説明                                                                                                                 |
| -------- | ------ | -- | --- | ------------------------------------------------------------------------------------------------------------------ |
| dept\_id | Number | はい | 100 | 削除する部門 ID。[部門リストの取得](/ja/open/development/user-management-acquires-the-list-departments) API で 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"
}
```

### エラーコード

当該 API の呼び出しでエラーが発生した場合は、エラーメッセージをもとに[グローバルエラーコード](/ja/open/development/server-api-error-codes-1)ドキュメントから解決方法をご確認ください。

| エラーコード（errcode） | エラーコードの説明（errmsg） | 解決方法                           |
| --------------- | ----------------- | ------------------------------ |
| 43007           | 権限付与が必要です         | access\_token に操作権限があるかご確認ください |
| 60003           | 対応する部門が見つかりません    | dept\_id が正しいかご確認ください          |
| 400002          | 無効なパラメータです        | パラメータが要件どおりに入力されているかご確認ください    |
| -1              | システムビジー           | 後で再度お試しください                    |
