Skip to main content

Delete a user with the .NET SDK

permitClient.Api.DeleteUser() deletes a user and all its related data from the environment that your API key belongs to. This reference is for .NET developers who remove users from backend code.

warning

DeleteUser removes the user and all its related data in one call. The .NET SDK has no method to restore a deleted user.

DeleteUser signature

public async Task DeleteUser(string userKey)

DeleteUser parameters

ParameterTypeRequiredDescription
userKeystringYesThe key of the user to delete. The user ID also works.

Example: delete a user with DeleteUser

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. DeleteUser returns a Task with no result:

await permitClient.Api.DeleteUser(userId);

DeleteUser return value and errors

DeleteUser returns a Task that completes when the user is deleted. The task has no result value.

If the Permit API returns an error, DeleteUser 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.