List tenants with the Node.js SDK
permit.api.tenants.list() lists the tenants in the Permit.io environment that your Node.js SDK client is connected to. This reference is for backend developers who read or search tenants from code.
Prerequisites
- A
permitclient created with an API key for the environment. See Create a Permit client.
Method signature
| Method | Signature |
|---|---|
permit.api.tenants.list | list(params?: IListTenantsParams): Promise<TenantRead[]> |
Parameters
permit.api.tenants.list() takes one optional object with these fields:
| Field | Type | Required | Description |
|---|---|---|---|
search | string | No | Text to match against the tenant name or key. |
page | number | No | Page number of the results, starting at 1. |
perPage | number | No | Number of results per page, up to 100. If you omit perPage, the Permit API applies its default page size. |
Example
The example fetches the first 20 tenants whose name or key matches example.
await permit.api.tenants.list({
search: "example",
page: 1,
perPage: 20,
});
Return value
The method resolves to an array of TenantRead objects, one per tenant on the requested page. Each object has key, id, name, description, attributes, created_at, updated_at, and last_action_at. To read every tenant, request the next page until the array has fewer items than perPage.
If the Permit API returns an error status code, the method throws a PermitApiError.