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.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Call this API to delete a specified department by its department ID, ensuring that the department has no sub-departments or members before deletion.
| Basic information | |
|---|---|
| HTTP URL | 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 |
| 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. |
| 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 API. |
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'
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());
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)
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");
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);
| 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. |
{
"errcode":0,
"errmsg": "ok",
"request_id": "6iq4zcul5zjp"
}
| 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. |
Was this page helpful?