Get a user with the .NET SDK
permitClient.Api.GetUser() fetches one user and its details from the environment that your API key belongs to. This reference is for .NET developers who read user data from backend code.
GetUser signature
public async Task<UserRead> GetUser(string userKey)
GetUser parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userKey | string | Yes | The key of the user. The user ID also works. |
Example: get a user with GetUser
The example uses a client named permitClient, created with new Permit(...) as shown in Check permissions with the .NET SDK. userId holds the key or ID of the user:
var user = await permitClient.Api.GetUser(userId);
GetUser return value and errors
On success, GetUser returns a UserRead with the user's Key, Id, Email, First_name, Last_name, and Attributes.
If the Permit API returns an error, GetUser throws a PermitApiException. The exception's StatusCode property has the HTTP status, such as 404 when no user with that key or ID exists, and its Response property has the response body.