---
type: api
title: Bulk delete roles
description: The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-bulk-delete-role
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-bulk-delete-role
products:
  - Elasticsearch
---

# Bulk delete roles

Availability: 8.15+

## Paths

- `DELETE` `/_security/role`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#bearerauth)

## Description

The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The bulk delete roles API cannot delete roles that are defined in roles files.

## Required authorization

* Cluster privileges: `manage_security`

## Query String Parameters

- `refresh` (enum Refresh)
  If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.
  Values: `true`, `false`, `wait_for`

## Request Body

`application/json`

- `names` ([] string) — required
  An array of role names to delete

## Response

`application/json`

- `deleted` ([] string)
  Array of deleted roles
- `not_found` ([] string)
  Array of roles that could not be found
- `errors` ({} BulkError)
  Present if any deletes resulted in errors
  - `count` (number)
    The number of errors
  - `details` (map string to ErrorCause)
    Details about the errors, keyed by role name
    Map values ({} ErrorCause)
    - `type` (string)
      The type of error
    - `reason` (union string) — nullable
      A human-readable explanation of the error, in English.
      One of: `string`
    - `stack_trace` (string)
      The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
    - `caused_by` ({} ErrorCause) — recursive
    - `root_cause` ([] ErrorCause) — recursive
    - `suppressed` ([] ErrorCause) — recursive
## Code Examples

#### Console

```console
DELETE /_security/role
{
  "names": ["my_admin_role", "my_user_role"]
}
```

#### JavaScript

```javascript
const response = await client.security.bulkDeleteRole({
  names: ["my_admin_role", "my_user_role"],
});
```

#### Python

```python
resp = client.security.bulk_delete_role(
    names=[
        "my_admin_role",
        "my_user_role"
    ],
)
```

#### curl

```curl
curl -X DELETE "$ELASTICSEARCH_URL/_security/role" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "names": [
      "my_admin_role",
      "my_user_role"
    ]
  }'
```

#### Java

```java
client.security().bulkDeleteRole(b -> b
    .names(List.of("my_admin_role","my_user_role"))
);
```

#### C#

```c#
var response = await client.Security
    .BulkDeleteRoleAsync(d1 => d1
        .Names("my_admin_role", "my_user_role")
    );
```

#### PHP

```php
$resp = $client->security()->bulkDeleteRole([
    "body" => [
        "names" => array(
            "my_admin_role",
            "my_user_role",
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.security.bulk_delete_role(
  body: {
    "names": [
      "my_admin_role",
      "my_user_role"
    ]
  }
)
```

## Response Examples

#### A successful response

A successful response from `DELETE /_security/role`.

```json
{
  "deleted": [
      "my_admin_role",
      "my_user_role"
  ]
}
```

#### A response with not_found roles

A partially successful response from `DELETE /_security/role`. If a role cannot be found, it appears in the `not_found` list in the response.

```json
{
  "deleted": [
      "my_admin_role"
  ],
  "not_found": [
      "not_an_existing_role"
  ]
}
```

#### A response with errors

A partially successful response from `DELETE /_security/role`. If part of a request fails or is invalid, the response includes `errors`.

```json
{
  "deleted": [
      "my_admin_role"
  ],
  "errors": {
      "count": 1,
      "details": {
          "superuser": {
              "type": "illegal_argument_exception",
              "reason": "role [superuser] is reserved and cannot be deleted"
          }
      }
  }
}
```

