Skip to main content

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

Method signature

MethodSignature
permit.api.tenants.listTenantUserslistTenantUsers(params: IListTenantUsers): Promise<PaginatedResultUserRead>

Parameters

permit.api.tenants.listTenantUsers() takes one object with these fields:

FieldTypeRequiredDescription
tenantKeystringYesKey or ID of the tenant.
searchstringNoText to match against the user email.
rolestringNoKey of a role. Returns only users with this role.
pagenumberNoPage number of the results, starting at 1.
perPagenumberNoNumber 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:

FieldTypeDescription
dataUserRead[]Users on the requested page. Each user has key, id, email, first_name, last_name, attributes, roles, and associated_tenants.
total_countnumberNumber of users that match the filters.
page_countnumberNumber of result pages.

If the tenant doesn't exist or the Permit API returns another error status code, the method throws a PermitApiError.