---
type: api
title: Get roles
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-security-get-role
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-security-get-role
products:
  - Elasticsearch
---

# Get roles


Availability:

## Paths

- `GET` `/_security/role/{name}`
- `GET` `/_security/role`

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

#### Path Parameters

- `name` (union Name | [] Name) — optional, leave it out to use `/_security/role`
  The name of the role.
You can specify multiple roles as a comma-separated list.
If you do not specify this parameter, the API returns information about all roles.

## Description

Get roles in the native realm.
The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The get roles API cannot retrieve roles that are defined in roles files.

## Required authorization

* Cluster privileges: `read_security`

## Response

`application/json`

Type: `map string to Role`

## Code Examples

#### Console

```console
GET /_security/role/my_admin_role
```

#### JavaScript

```javascript
const response = await client.security.getRole({
  name: "my_admin_role",
});
```

#### Python

```python
resp = client.security.get_role(
    name="my_admin_role",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_security/role/my_admin_role" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().getRole(g -> g
    .name("my_admin_role")
);
```

#### C#

```c#
var response = await client.Security
    .GetRoleAsync(d1 => d1
        .Name(new[] { "my_admin_role" })
    );
```

#### PHP

```php
$resp = $client->security()->getRole([
    "name" => "my_admin_role",
]);
```

#### Ruby

```ruby
response = client.security.get_role(
  name: "my_admin_role"
)
```

## Response Examples

#### Security get role response example1

A successful response from `GET /_security/role/my_admin_role`. The response contains information about the `my_admin_role` role in the native realm.

```json
{
  "my_admin_role": {
    "description": "Grants full access to all management features within the cluster.",
    "cluster" : [ "all" ],
    "indices" : [
      {
        "names" : [ "index1", "index2" ],
        "privileges" : [ "all" ],
        "allow_restricted_indices" : false,
        "field_security" : {
          "grant" : [ "title", "body" ]}
      }
    ],
    "applications" : [ ],
    "run_as" : [ "other_user" ],
    "metadata" : {
      "version" : 1
    },
    "transient_metadata": {
      "enabled": true
    }
  }
}
```

