See api-docs Menu

Get Roles

This call returns up to 50 roles per page.

For details about using the pagination element to easily “page” through roles, see Query Parameters.

To get roles assigned to a user, use the Get Roles for a User API.

To assign one or more existing roles to user, use the Assign Role to User API.

To remove one or more roles from a user, use the Remove Role from User API.

Resource URL

https://api.<us_or_eu>.onelogin.com/api/1/roles

Header Parameters

Authorization

required

string

Set to bearer:<access_token>.

Set <access_token> to the access token you generated using the Generate Token API.

The access token must have been generated using an API credential pair created using the scope required to call this API. This API can be called using either of the following scopes: Read Users, Manage users, Read All, or Manage All.

Query Parameters

For details about how to search for roles using these query parameters, see Search.

  • id

  • name

The following examples illustrate how to use various query parameters to return subsets of roles:

  • Return the role whose name value equals employee

    https://api.us.onelogin.com/api/1/roles?name=employee

  • Include wildcards. For example, you can return all roles whose name values end with -us:

    https://api.us.onelogin.com/api/1/roles?name=*-us

  • Return a limited number of roles:

    https://api.us.onelogin.com/api/1/roles?limit=10

  • Return roles sorted by id. Use + to sort in ascending order or - to sort in descending order:

    https://api.us.onelogin.com/api/1/roles?sort=+id

  • Return roles displaying only selected fields per role:

    https://api.us.onelogin.com/api/1/roles?fields=id

  • Combine use of multiple query parameters using an &:

    https://api.us.onelogin.com/api/1/roles?name=*-us&sort=+id&fields=id

For more details, see Using Query Parameters.

Sample Response

{
    "status": {
        "error": false,
        "code": 200,
        "type": "success",
        "message": "Success"
    },
    "pagination": {
        "before_cursor": null,
        "after_cursor": null,
        "previous_link": null,
        "next_link": null
    },
    "data": [
        {
            "id": 1111,
            "name": "C-Executive"
        },
        {
            "id": 1112,
            "name": "Contractor"
        },
        {
            "id": 1113,
            "name": "Default"
        },
        {
            "id": 1114,
            "name": "Employee"
        }
    ]
}

Typically, this error means that your Authorization header value is missing or incorrectly formatted. The Authorization header value should use this format: bearer:<access_token>.

{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": "Authorization Information is incorrect"
    }
}

Typically, this error means that your access token value is invalid.

{
    "status": {
        "error": true,
        "code": 401,
        "type": "Unauthorized",
        "message": "Authentication Failure"
    }
}

Response Elements

For more information about the pagination element, see Query Parameters.

id Role’s unique ID in OneLogin.
name Role name.

Postman Collection

Be sure to set Postman-specific environment variables indicated by {{ }}.

Download for the Roles API

Sample Code

cURL

Replace sample values indicated by < > with your actual values.

Get Roles

curl 'https://api.<us_or_eu>.onelogin.com/api/1/roles' \
-X GET \
-H "Authorization: bearer:<access_token>"

Get Roles by Name

curl 'https://api.<us_or_eu>.onelogin.com/api/1/roles?name=<name>' \
-X GET \
-H "Authorization: bearer:<access_token>"

Python

See Work with OAuth 2.0 Tokens, Users, and Roles.


Have a Question?

Have a how-to question? Seeing a weird error? Ask us about it on StackOverflow.

Found a bug? Submit a support ticket.

Have a product idea or request? Share it with us in our Ideas Portal.