Skip to main content

Delete a tenant with the Go SDK

Permit.Api.Tenants.Delete() deletes a tenant and all its related data from the environment that your API key belongs to. This reference is for Go developers who manage tenants from backend code.

warning

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

Tenants.Delete signature

func (t *Tenants) Delete(ctx context.Context, tenantKey string) error

Tenants.Delete parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
tenantKeystringYesThe key of the tenant to delete. The tenant ID also works.

Example: delete a tenant with Tenants.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 tenantKey with the key of your tenant:

err := Permit.Api.Tenants.Delete(ctx, "tenantKey")

Tenants.Delete return value and errors

Tenants.Delete returns only an error, which is nil when the tenant 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 tenant 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.