Skip to main content

List resource instances with the Node.js SDK

permit.api.resourceInstances.list() lists the resource instances in the Permit.io environment that your Node.js SDK client is connected to. A resource instance is one object of a resource type, such as the file file:budget-2024 of the file resource. Relationship-based access control (ReBAC) policies grant roles on resource instances. This reference is for backend developers who read resource instances from code.

Prerequisites

Method signature

MethodSignature
permit.api.resourceInstances.listlist(params?: IListResourceInstanceParams): Promise<ResourceInstanceRead[]>

Parameters

permit.api.resourceInstances.list() takes one optional object with these fields:

FieldTypeRequiredDescription
tenantstringNoKey or ID of the tenant.
resourcestringNoKey or ID of the resource type.
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 lists the first 20 instances of the file resource in the default tenant.

await permit.api.resourceInstances.list({
tenant: "default",
resource: "file",
page: 1,
perPage: 20,
});

Return value

The method resolves to an array of ResourceInstanceRead objects, one per instance on the requested page:

FieldTypeDescription
keystringKey of the instance. Pass the key in the resource of permit.check().
resourcestringKey of the resource type.
tenantstringKey of the tenant that the instance belongs to.
attributesobjectInstance attributes.
id, resource_id, tenant_idstringIDs of the instance, resource type, and tenant.
organization_id, project_id, environment_idstringIDs of the organization, project, and environment.
created_at, updated_atstringISO 8601 timestamps.

To read every instance, 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.