Skip to main content

List tenants with the Go SDK

Permit.Api.Tenants.List() returns one page of the tenants in the environment that your API key belongs to. This reference is for Go developers who read tenant data from backend code.

Tenants.List signature

func (t *Tenants) List(ctx context.Context, page int, perPage int) ([]models.TenantRead, error)

Tenants.List parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
pageintYesThe page number to fetch, starting at 1.
perPageintYesThe number of tenants per page, from 1 to 100.

Example: list tenants with Tenants.List

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. The call fetches the first page, with up to 10 tenants:

tenants, err := Permit.Api.Tenants.List(ctx, 1, 10)

To read every tenant, call Tenants.List with page set to 1, 2, 3, and so on, until the returned slice has fewer than perPage items.

Tenants.List return value and errors

On success, Tenants.List returns a []models.TenantRead. Each item has the tenant's Key, Id, Name, Description, and Attributes.

Tenants.List checks the pagination values before it calls the Permit API. If page is less than 1, or perPage is less than 1 or greater than 100, err holds an errors.PermitError with the ErrorCode PaginationError.

warning

When the Permit API call itself fails, Tenants.List logs the error and returns a nil error. An empty or nil slice can mean that the call failed, so check the SDK logs when you expect tenants and get none.