> For the complete documentation index, see [llms.txt](https://docs.datasentinel.io/manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datasentinel.io/manual/implementation/platform-usage/api-reference/role.md).

# Role

{% hint style="info" %}
Managing roles is the initial step in implementing[ role-based access](/manual/features/other-features/role-based-access.md)
{% endhint %}

To use the Role API, it's necessary to generate an access token.

{% content-ref url="/pages/pWMV9FXn2PVthWicFKyC" %}
[Access Token](/manual/implementation/platform-usage/api-reference/access-token.md)
{% endcontent-ref %}

{% hint style="info" %}
A comprehensive toolkit, with practical usage examples, is accessible on [GitHub](https://github.com/datasentinel/datasentinel_toolkit).

This toolkit comes pre-installed as a default component within the on-premises platform, located at `/datasentinel/soft/datasentinel_toolkit`.
{% endhint %}

## **Role**

## Add

<mark style="color:green;">`POST`</mark> `https://<<platform-server>>/ds-api/roles/{role}`

Create a New Role

#### Path Parameters

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| role<mark style="color:red;">\*</mark> | String | Role Name   |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

#### Request Body

| Name                                     | Type  | Description      |
| ---------------------------------------- | ----- | ---------------- |
| access<mark style="color:red;">\*</mark> | Array | Array of Filters |

**Response**

{% tabs %}
{% tab title="201: Created " %}

```json
{
  "status": "Role name <<role>> created successfully"
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="409: Conflict " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

The JSON array structure should adhere to the following format:

```json
"access": [
 {
    "filters": [
        {"tag": "tag_name", "value": "tag_value"},
        {"tag": "another_tag", "value": "another_value"},
        ...
    ]
 }
]
```

{% hint style="info" %}
It's important to note that the specified tags must already exist and be linked to one or more instances.
{% endhint %}

```json
// Example: 
// Establish a role-based access that exclusively applies to instances 
// categorized as "production" 
// AND situated within the "London" datacenter.
"access": [
 {
    "filters":
      [
              {"tag": "environment", "value": "production"},
              {"tag": "datacenter", "value": "london"}
      ]
 }
]
```

```json
// Example:
// Establish a role-based access that encompasses instances 
// categorized as either "development" OR "uat"
"access": [
  {
    "filters":
      [
        { "tag": "environment", "value": "development" }
      ]
  },
  {
    "filters":
      [
        { "tag": "environment", "value": "uat" }
      ]
  },
]

```

{% hint style="info" %}
You can combine multiple AND/OR conditions within the JSON array
{% endhint %}

## Display

<mark style="color:blue;">`GET`</mark> `https://<<platform-server>>/ds-api/roles/{role}`

Display Role Attributes

#### Path Parameters

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| role<mark style="color:red;">\*</mark> | String | Role Name   |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}
{% code title="Example" %}

```json
{
"name": "myRole",
"access": [
    {
        "filters": [
            {
                "tag": "pg_instance",
                "value": "51.15.233.24@agentLess6"
            }
        ]
    },
    {
        "filters": [
            {
                "tag": "pg_instance",
                "value": "51.158.104.206@agentLess11"
            }
        ]
    }
  ]
}

```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

## Assigned Users

<mark style="color:blue;">`GET`</mark> `https://<<platform-server>>/ds-api/roles/{role}/users`

Display the users assigned to a specific role

#### Path Parameters

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| role<mark style="color:red;">\*</mark> | String | Role Name   |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}
{% code title="Example" %}

```json
[
  {
      "id": 70,
      "login": "username",
      "email": "userName@myCompany.com",
      "profile": "data admin",
      "privilege": "admin",
      "role": "myRole",
      "live_360": 1
  }
]
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

## Replace

<mark style="color:orange;">`PUT`</mark> `https://<<platform-server>>/ds-api/roles/{role}`

Replace existing role

#### Path Parameters

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| role<mark style="color:red;">\*</mark> | String | Role Name   |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

#### Request Body

| Name                                     | Type  | Description      |
| ---------------------------------------- | ----- | ---------------- |
| access<mark style="color:red;">\*</mark> | Array | Array of Filters |

**Response**

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "status": "Role name <<role>> updated successfully"
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

<mark style="color:red;">`DELETE`</mark> `https://<<platform-server>>/ds-api/roles/{role}`

Delete Role

#### Path Parameters

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| role<mark style="color:red;">\*</mark> | String | Role Name   |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "status": "Role name <<role>> deleted successfully"
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

## Roles

## Display

<mark style="color:blue;">`GET`</mark> `https://<<platform-server>>/ds-api/roles`

Display All Roles

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}
{% code title="Example" %}

```json
[
  {
      "name": "myRole",
      "access": [
          {
              "filters": [
                  {
                      "tag": "pg_instance",
                      "value": "51.15.233.24@agentLess6"
                  }
              ]
          },
          {
              "filters": [
                  {
                      "tag": "pg_instance",
                      "value": "51.158.104.206@agentLess11"
                  }
              ]
          }
      ]
  },
  {
      "name": "testrole",
      "access": [
          {
              "filters": [
                  {
                      "tag": "pg_version",
                      "value": "11.8"
                  },
                  {
                      "tag": "pg_instance",
                      "value": "51.15.233.24@agentLess6"
                  }
              ]
          }
      ]
  }
]
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.datasentinel.io/manual/implementation/platform-usage/api-reference/role.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
