Skip to main content

List tenants with the Java SDK

permit.api.tenants.list() fetches one page of the tenants in your Permit environment. A tenant is an isolated group of users and resources, such as one customer organization in a multi-tenant application. This reference is for Java developers who read tenants from code. The examples assume an initialized Permit client named permit, as set up in Check permissions with the Java SDK.

Signature

OverloadBehavior
TenantRead[] list()Fetches page 1 with 100 results per page.
TenantRead[] list(int page)Fetches the given page with 100 results per page.
TenantRead[] list(int page, int perPage)Fetches the given page with the given page size.

All overloads throw IOException, PermitApiError, and PermitContextError.

Parameters

ParameterTypeRequiredDescription
pageintNoThe page number to fetch, starting at 1. Defaults to 1.
perPageintNoThe number of results per page. Defaults to 100.

Example

The example fetches the first page of tenants. To fetch another page, pass the page number, for example permit.api.tenants.list(2, 50). The example uses TenantRead from io.permit.sdk.openapi.models.

import io.permit.sdk.openapi.models.TenantRead;

TenantRead[] tenants = permit.api.tenants.list();

Return value

list() returns an array of TenantRead objects (io.permit.sdk.openapi.models.TenantRead). The array is empty when the page has no tenants. The array does not include a total count.

To list the users of one tenant, call permit.api.tenants.listTenantUsers(tenantKey). The method takes the same optional page and perPage parameters and returns a PaginatedResultUserRead.

Exceptions

All exception classes except IOException are in the io.permit.sdk.api package.

ExceptionThrown when
IOExceptionThe HTTP request to the Permit API fails, for example because of a network error.
PermitApiErrorThe Permit API returns an error status code. getResponseCode() returns the HTTP status code and getRawResponse() returns the response body.
PermitContextErrorThe SDK context does not include an environment, for example because the API key is scoped to an organization or project.