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

# 删除角色

> 调用本接口根据角色 ID 删除指定的角色,含请求参数、调用方式与响应字段说明。

调用本接口，根据角色ID删除指定的角色。

## 接口调用说明

* 在调用该接口前，确保与要删除的角色关联的员工都已删除该角色。
* 不允许删除默认角色组下的角色。

## 请求

| **基本信息**    |                                                                                                  |
| ----------- | ------------------------------------------------------------------------------------------------ |
| HTTP URL    | [https://api.dingtalk.io/topapi/role/deleterole](https://api.dingtalk.io/topapi/role/deleterole) |
| HTTP Method | POST                                                                                             |
| 支持的应用类型     | appType-企业内部应用                                                                                   |
| 权限要求        | permission-qyapi\_manage\_addresslist-通讯录数据管理权限                                                  |

### 查询参数

| 名称            | 类型     | 是否必填 | 示例值      | 描述                                                                                   |
| ------------- | ------ | ---- | -------- | ------------------------------------------------------------------------------------ |
| access\_token | String | 是    | 6ed1xxxx | 调用该接口的应用凭证，通过[获取企业内部应用的access\_token](/zh/open/development/obtain-orgapp-token)接口获取。 |

### 请求体

| 名称       | 类型     | 是否必填 | 示例值        | 描述                                                                                                                       |
| -------- | ------ | ---- | ---------- | ------------------------------------------------------------------------------------------------------------------------ |
| role\_id | Number | 是    | 1581321999 | 要删除的角色ID，可以调用[获取角色列表](/zh/open/development/obtains-a-list-of-enterprise-roles)接口获取。  “默认”分组内的角色不支持修改，包括：负责人、主管、主管理员、子管理员 |

### 请求示例

```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);
```

## 响应

### 响应体

| 名称          | 类型     | 示例值          | 描述     |
| ----------- | ------ | ------------ | ------ |
| errcode     | Number | 0            | 返回码。   |
| errmsg      | String | ok           | 返回码描述。 |
| request\_id | String | zw9fhpj3m32u | 请求ID。  |

### 响应体示例

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

### 错误码

若调用该接口报错，可根据错误信息在[全局错误码](/zh/open/development/server-api-error-codes-1)文档中查找解决方案。

| 错误码（errcode） | 错误码描述（errmsg） | 解决方案            |
| ------------ | ------------- | --------------- |
| 33011        | 无效的role\_id   | 请校验role\_id是否正确 |
| 23004        | 不允许编辑系统标签     | 请校验role\_id是否合法 |
| 1002         | 系统繁忙          | 请稍后再试           |
