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.
| Parameter | Type | Default | Description |
|---|---|---|---|
search | string | null | Text to search for in the role name or key. |
page | int | 1 | The page number to fetch, starting at 1. |
perPage | int | 30 | The 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:
| Property | Type | Description |
|---|---|---|
Data | ICollection<RoleRead> | The roles on the requested page. |
Total_count | int | The number of roles that match the search, across all pages. |
Page_count | int? | 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.