Skip to main content

List relationship tuples with the Node.js SDK

permit.api.relationshipTuples.list() lists the relationship tuples in the Permit.io environment that your Node.js SDK client is connected to. A relationship tuple states that a relation, such as parent or owner, exists between a subject resource instance and an object resource instance. Relationship-based access control (ReBAC) policies derive permissions from these tuples. This reference is for backend developers who read the relationship graph from code.

Prerequisites

Method signature

MethodSignature
permit.api.relationshipTuples.listlist(params: IListRelationshipTuples): Promise<RelationshipTupleRead[]>

Parameters

permit.api.relationshipTuples.list() takes one object. Every field is optional. Pass {} to list tuples without filters.

FieldTypeRequiredDescription
tenantstringNoKey or ID of the tenant.
relationstringNoKey or ID of the relation.
subjectstringNoSubject resource instance, as an ID or in the format resource_type:resource_instance_key.
subjectTypestringNoKey or ID of the subject resource type.
objectstringNoObject resource instance, as an ID or in the format resource_type:resource_instance_key.
objectTypestringNoKey or ID of the object 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.

The SDK always returns an array of tuples without a total count.

Example

The example lists the parent relationship tuples between file:file-1 and folder:folder-1 in the default tenant.

await permit.api.relationshipTuples.list({
tenant: "default",
relation: "parent",
subject: "file:file-1",
subjectType: "file",
object: "folder:folder-1",
objectType: "folder",
page: 1,
perPage: 20
});

Return value

The method resolves to an array of RelationshipTupleRead objects:

[
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"subject": "organization:permitio",
"relation": "owner",
"object": "repo:opal",
"tenant": "default",
"subject_id": "7c60d51f-b44e-4682-87d6-449835ea4d11",
"relation_id": "405d8375-3514-403b-8c43-83ae74cfe022",
"object_id": "12f84e49-af17-4b0c-8cd7-01258769c2ba",
"tenant_id": "40ef0e48-a11f-4963-a229-e396c9f7e733",
"organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6",
"project_id": "405d8375-3514-403b-8c43-83ae74cfe0e9",
"environment_id": "40ef0e48-a11f-4963-a229-e396c9f7e7c4",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]

FieldDescription
subject, relation, object, tenantKeys of the subject instance, relation, object instance, and tenant of the tuple.
idUnique ID of the tuple.
subject_id, relation_id, object_id, tenant_idIDs of the subject instance, relation, object instance, and tenant.
organization_id, project_id, environment_idIDs of the organization, project, and environment.
created_at, updated_atISO 8601 timestamps.

If the Permit API returns an error status code, the method throws a PermitApiError.

Paginated response of the Permit API

When you call the list relationship tuples API endpoint directly with the include_total_count=true query parameter, the API wraps the tuples in an object with a total count. The Node.js SDK method doesn't return this shape.

{
"data": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"subject": "organization:permitio",
"relation": "owner",
"object": "repo:opal",
"tenant": "default",
"subject_id": "7c60d51f-b44e-4682-87d6-449835ea4d11",
"relation_id": "405d8375-3514-403b-8c43-83ae74cfe022",
"object_id": "12f84e49-af17-4b0c-8cd7-01258769c2ba",
"tenant_id": "40ef0e48-a11f-4963-a229-e396c9f7e733",
"organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6",
"project_id": "405d8375-3514-403b-8c43-83ae74cfe0e9",
"environment_id": "40ef0e48-a11f-4963-a229-e396c9f7e7c4",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
],
"total_count": 1,
"page_count": 1
}