List the roles assigned to a user with the .NET SDK
permitClient.Api.ListAssignedRoles() returns the role assignments that a user holds in any tenant of the environment that your API key belongs to. This reference is for .NET developers who read a user's roles from backend code.
ListAssignedRoles signature
public async Task<PaginatedResult_RoleAssignmentRead_> ListAssignedRoles(string userId, string roleId = null, string tenantId = null, string resourceId = null, string instanceId = null)
ListAssignedRoles parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | The key of the user. The user ID also works. |
roleId | string | No | Accepted but not sent to the Permit API. |
tenantId | string | No | Accepted but not sent to the Permit API. |
resourceId | string | No | Accepted but not sent to the Permit API. |
instanceId | string | No | Accepted but not sent to the Permit API. |
ListAssignedRoles filters only by user. The method passes userId to the Permit API and ignores the other arguments, so the result includes the user's role assignments in every tenant. The method also sends no page or perPage value, so the Permit API returns the first page with its default page size. To filter by tenant or to page through results, call GetAssignedRoles(userKey, tenantKey) on permitClient.Api instead. GetAssignedRoles also accepts roleKey, resourceKey, instanceKey, page, and perPage arguments.
Example: list a user's roles with ListAssignedRoles
The example uses a client named permitClient, created with new Permit(...) as shown in Check permissions with the .NET SDK. userId holds the key of the user:
var roles = await permitClient.Api.ListAssignedRoles(userId);
ListAssignedRoles return value and errors
On success, ListAssignedRoles returns a PaginatedResult_RoleAssignmentRead_ with these properties:
| Property | Type | Description |
|---|---|---|
Data | ICollection<RoleAssignmentRead> | The role assignments on the page. Each item has the User, Role, Tenant, and Resource_instance of one assignment. |
Total_count | int | The number of role assignments the user holds, across all pages. |
Page_count | int? | The number of pages. |
If the Permit API returns an error, ListAssignedRoles throws a PermitApiException. The exception's StatusCode property has the HTTP status, and its Response property has the response body.