Skip to main content

Update a tenant with the Go SDK

Permit.Api.Tenants.Update() changes the name, description, or attributes of an existing tenant in the environment that your API key belongs to. This reference is for Go developers who manage tenants from backend code.

Tenants.Update signature

func (t *Tenants) Update(ctx context.Context, tenantKey string, tenantUpdate models.TenantUpdate) (*models.TenantRead, error)

Tenants.Update parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
tenantKeystringYesThe key of the tenant to update. The tenant ID also works.
tenantUpdatemodels.TenantUpdateYesThe fields to change. Build it with models.NewTenantUpdate().

TenantUpdate fields

Tenants.Update is a partial update. The Permit API changes only the fields you set, and each field you set replaces the stored value completely. For example, setting Attributes replaces all the tenant's attributes, not only the keys you pass.

FieldTypeRequiredDescription
Name*stringNoA descriptive name for the tenant. Set it with SetName().
Description*stringNoA longer description of the tenant. Set it with SetDescription().
Attributesmap[string]interface{}NoTenant attributes that attribute-based access control (ABAC) policies evaluate. Set them with SetAttributes().

Example: rename a tenant with Tenants.Update

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.

Build the TenantUpdate struct with the new name:

tenantUpdate := models.NewTenantUpdate()
tenantUpdate.SetName("New Tenant Name")

Pass the key of the tenant and the struct to Tenants.Update:

tenant, err := Permit.Api.Tenants.Update(ctx, "tenant-key", *tenantUpdate)

Tenants.Update return value and errors

On success, Tenants.Update returns a *models.TenantRead with the updated tenant.

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.
UnprocessableEntityErrorHTTP 422: a field failed validation.
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.