Skip to main content

List roles with the Java SDK

permit.api.roles.list() fetches one page of the roles in your Permit environment. This reference is for Java developers who read role-based access control (RBAC) roles from code. The examples assume an initialized Permit client named permit, as set up in Check permissions with the Java SDK.

Signature

OverloadBehavior
RoleRead[] list()Fetches page 1 with 100 results per page.
RoleRead[] list(int page)Fetches the given page with 100 results per page.
RoleRead[] list(int page, int perPage)Fetches the given page with the given page size.

All overloads throw IOException, PermitApiError, and PermitContextError.

Parameters

ParameterTypeRequiredDescription
pageintNoThe page number to fetch, starting at 1. Defaults to 1.
perPageintNoThe number of results per page. Defaults to 100.

Example

The example fetches the first page of roles. To fetch another page, pass the page number, for example permit.api.roles.list(2, 50). The example uses RoleRead from io.permit.sdk.openapi.models.

import io.permit.sdk.openapi.models.RoleRead;

RoleRead[] roles = permit.api.roles.list();

Return value

list() returns an array of RoleRead objects (io.permit.sdk.openapi.models.RoleRead). The array is empty when the page has no roles. The array does not include a total count.

Exceptions

All exception classes except IOException are in the io.permit.sdk.api package.

ExceptionThrown when
IOExceptionThe HTTP request to the Permit API fails, for example because of a network error.
PermitApiErrorThe Permit API returns an error status code. getResponseCode() returns the HTTP status code and getRawResponse() returns the response body.
PermitContextErrorThe SDK context does not include an environment, for example because the API key is scoped to an organization or project.