Get a role with the .NET SDK
permitClient.Api.GetRole() fetches one role and its details from 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.
GetRole signature
public async Task<RoleRead> GetRole(string roleKey)
GetRole parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
roleKey | string | Yes | The key of the role. The role ID also works. |
Example: get a role with GetRole
The example uses a client named permitClient, created with new Permit(...) as shown in Check permissions with the .NET SDK. roleId holds the key or ID of the role. The result is one RoleRead, even though the sample names the variable roles:
var roles = await permitClient.Api.GetRole(roleId);
GetRole return value and errors
On success, GetRole returns a RoleRead with the role's Key, Id, Name, Description, Permissions, and Extends.
If the Permit API returns an error, GetRole throws a PermitApiException. The exception's StatusCode property has the HTTP status, such as 404 when no role with that key or ID exists, and its Response property has the response body.