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.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | The context of the request. |
tenantKey | string | Yes | The 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:
ErrorCode | Cause |
|---|---|
NotFound | HTTP 404: no tenant with that key or ID exists in the environment. |
Unauthorized, ForbiddenAccess | HTTP 401 or 403: the API key is invalid or has no access to the environment. |
UnexpectedError | A server error (HTTP 5xx) or a network error. |