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

> Call this API to delete a specified role by role ID, with request parameters, invocation details, and response fields.

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 URL              | [https://api.dingtalk.io/topapi/role/deleterole](https://api.dingtalk.io/topapi/role/deleterole) |
| HTTP Method           | POST                                                                                             |
| Supported app type    | appType-Internal app                                                                             |
| Permission required   | permission-qyapi\_manage\_addresslist-Contacts data management permission                        |

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                   |
| ------------- | ------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | 6ed1xxxx | The app credential for calling 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                                                                                                                                                                                                                             |
| -------- | ------ | -------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| role\_id | Number | Yes      | 1581321999 | The ID of the role to delete. Call the [Get role list](/open/development/obtains-a-list-of-enterprise-roles) API to obtain it.  Roles in the "Default" group cannot be modified, including: Owner, Manager, Super Admin, and Sub Admin. |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.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

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

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

req.role_id=11
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 OapiRoleDeleteroleRequest;
$req->setRoleId("11");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/role/deleterole");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.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

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

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode":"0",
  "request_id":"zw9fhpj3m32u"
}
```

### Error codes

If an error is returned when calling this API, refer to the [Global error codes](/open/development/server-api-error-codes-1) document to find the solution based on the error message.

| Error code (errcode) | Error message (errmsg)             | Solution                         |
| -------------------- | ---------------------------------- | -------------------------------- |
| 33011                | Invalid role\_id                   | Verify that role\_id is correct. |
| 23004                | Editing system tags is not allowed | Verify that role\_id is valid.   |
| 1002                 | System busy                        | Try again later.                 |
