Skip to main content
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 URLhttps://oapi.dingtalk.io/topapi/v2/department/delete
HTTP MethodPOST
Supported app typeappType-Internal app
Required permissionspermission-qyapi_manage_addresslist-Contacts data management permission

Query parameters

NameTypeRequiredExampleDescription
access_tokenStringYesbE74xxxxThe app credential used to call this API. Obtain it through the API for getting the access_token of an internal app.

Request body

NameTypeRequiredExampleDescription
dept_idNumberYes100The ID of the department to delete. You can obtain the dept_id value through the Get department list API.

Request example

curl -X POST "https://oapi.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
DingTalkClient client = new DefaultDingTalkClient("https://oapi.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
import dingtalk.api

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

req.dept_id=100
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
PHP
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://oapi.dingtalk.io/topapi/v2/department/delete");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.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

NameTypeExampleDescription
errcodeNumber0The return code.
errmsgStringokThe description of the return code.
request_idString6iq4zcul5zjpThe request ID.

Response example

{
 "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 document.
Error code (errcode)Error message (errmsg)Solution
43007Authorization requiredConfirm that the access_token has the required permissions.
60003Department not foundConfirm that the dept_id is correct.
400002Invalid parameterConfirm that the parameters are entered as required.
-1System busyTry again later.