List the users of a tenant with the Node.js SDK
permit.api.tenants.listTenantUsers() lists the users that belong to one tenant in the Permit.io environment that your Node.js SDK client is connected to. This reference is for backend developers who show or audit the members of a customer organization 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.listTenantUsers | listTenantUsers(params: IListTenantUsers): Promise<PaginatedResultUserRead> |
Parameters
permit.api.tenants.listTenantUsers() takes one object with these fields:
| Field | Type | Required | Description |
|---|---|---|---|
tenantKey | string | Yes | Key or ID of the tenant. |
search | string | No | Text to match against the user email. |
role | string | No | Key of a role. Returns only users with this role. |
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 up to 100 users of the default tenant who have the admin role and have @permit.io in their email.
await permit.api.tenants.listTenantUsers({
tenantKey: "default",
search: "@permit.io",
role: "admin",
page: 1,
perPage: 100,
});
Return value
The method resolves to a PaginatedResultUserRead object:
| Field | Type | Description |
|---|---|---|
data | UserRead[] | Users on the requested page. Each user has key, id, email, first_name, last_name, attributes, roles, and associated_tenants. |
total_count | number | Number of users that match the filters. |
page_count | number | Number of result pages. |
If the tenant doesn't exist or the Permit API returns another error status code, the method throws a PermitApiError.