See api-docs Menu

Get Roles

Try Roles v2

A new version of this API is now available that offers the ability to create, update and manage 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://<subdomain>/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://<subdomain>.onelogin.com/api/1/roles?name=employee

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

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

  • Return a limited number of roles:

    https://<subdomain>.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://<subdomain>.onelogin.com/api/1/roles?sort=+id

  • Return roles displaying only selected fields per role:

    https://<subdomain>.onelogin.com/api/1/roles?fields=id

  • Combine use of multiple query parameters using an &:

    https://<subdomain>.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://<subdomain>/api/1/roles' \
-X GET \
-H "Authorization: bearer:<access_token>"

Get Roles by Name

curl 'https://<subdomain>/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?

Found a problem or a bug? Submit a support ticket.

Looking for walkthroughs or how-to guides on OneLogin's user and admin features? Check out the documentation in our Knowledge Base.

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