Skip to main content
Call this API to delete a specified role by role ID.

API call description

  • Before calling this API, make sure that all employees associated with the role have had the role removed.
  • Roles under the default role group cannot be deleted.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/role/deleterole
HTTP MethodPOST
Supported app typeappType-Internal app
Permission requiredpermission-qyapi_manage_addresslist-Contacts data management permission

Query parameters

NameTypeRequiredExampleDescription
access_tokenStringYes6ed1xxxxThe app credential for calling this API. Obtain it through the API for getting the access_token of an internal app.

Request body

NameTypeRequiredExampleDescription
role_idNumberYes1581321999The ID of the role to delete. Call the Get role list API to obtain it. Roles in the “Default” group cannot be modified, including: Owner, Manager, Super Admin, and Sub Admin.

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/role/deleterole" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=f5326exxxxbe8d071' \
-d 'role_id=11'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/role/deleterole");
OapiRoleDeleteroleRequest req = new OapiRoleDeleteroleRequest();
req.setRoleId(1581321999L);
OapiRoleDeleteroleResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

req=dingtalk.api.OapiRoleDeleteroleRequest("https://oapi.dingtalk.io/topapi/role/deleterole")

req.role_id=11
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 OapiRoleDeleteroleRequest;
$req->setRoleId("11");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/role/deleterole");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/role/deleterole");
OapiRoleDeleteroleRequest req = new OapiRoleDeleteroleRequest();
req.RoleId = 11L;
OapiRoleDeleteroleResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

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

Response body example

{
  "errcode":"0",
  "request_id":"zw9fhpj3m32u"
}

Error codes

If an error is returned when calling this API, refer to the Global error codes document to find the solution based on the error message.
Error code (errcode)Error message (errmsg)Solution
33011Invalid role_idVerify that role_id is correct.
23004Editing system tags is not allowedVerify that role_id is valid.
1002System busyTry again later.