Skip to main content

Delete a user with the Go SDK

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

warning

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

Users.Delete signature

func (u *Users) Delete(ctx context.Context, userKey string) error

Users.Delete parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
userKeystringYesThe key of the user to delete. The user ID also works.

Example: delete a user with Users.Delete

The example uses a client named Permit, created with permit.NewPermit() as shown in Check permissions with the Go SDK, and a ctx of type context.Context. Replace user-key with the key of your user:

err := Permit.Api.Users.Delete(ctx, "user-key")

Users.Delete return value and errors

Users.Delete returns only an error, which is nil when the user is deleted.

If the call fails, err holds an errors.PermitError from the github.com/permitio/permit-golang/pkg/errors package. Its StatusCode field has the HTTP status, and its ErrorCode field has one of these codes:

ErrorCodeCause
NotFoundHTTP 404: no user with that key or ID exists in the environment.
Unauthorized, ForbiddenAccessHTTP 401 or 403: the API key is invalid or has no access to the environment.
UnexpectedErrorA server error (HTTP 5xx) or a network error.