Skip to main content

List roles with the .NET SDK

permitClient.Api.ListRoles() returns one page of the roles in the environment that your API key belongs to. This reference is for .NET developers who read role-based access control (RBAC) roles from backend code.

ListRoles signature

public async Task<PaginatedResult_RoleRead_> ListRoles(string search = default, int page = 1, int perPage = 30)

ListRoles parameters

All parameters are optional.

ParameterTypeDefaultDescription
searchstringnullText to search for in the role name or key.
pageint1The page number to fetch, starting at 1.
perPageint30The number of roles per page. The Permit API accepts at most 100.

Example: list roles with ListRoles

The example uses a client named permitClient, created with new Permit(...) as shown in Check permissions with the .NET SDK. The call uses the defaults, so it returns the first 30 roles:

var response = await permitClient.Api.ListRoles();

ListRoles return value and errors

On success, ListRoles returns a PaginatedResult_RoleRead_ with these properties:

PropertyTypeDescription
DataICollection<RoleRead>The roles on the requested page.
Total_countintThe number of roles that match the search, across all pages.
Page_countint?The number of pages.

If the Permit API returns an error, ListRoles throws a PermitApiException. The exception's StatusCode property has the HTTP status, such as 422 when perPage is greater than 100, and its Response property has the response body.