Overview
Retrieve relationship tuples that exist inside a specific environment and filter them.
Check the API documentation for more information.
Get All relationship tuples
First of all we need to get our API_SECRET_KEY from the dashboard and get the current project_id and env_id
Replace API_SECRET_KEY with the key from the Permit dashboard along with the project_id and env_id you got from the API in the following command.
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
The return user object will look like this:
[
    {
        "subject": "Folder:documents",
        "relation": "parent",
        "object": "File:my_pdf",
        "id": "c76f9a129dbe44f88664b7333fef0cce",
        "tenant": "default",
        "subject_id": "6e6855d2b2cf438c9bf79136ec72c188",
        "relation_id": "9c6aee683f5c482cabd2d536734801c9",
        "object_id": "3bdd97e40010426bbf0648d962779122",
        "tenant_id": "f9bcad6ad2a54113ba4f45fc014d4bb0",
        "organization_id": "78f198a252c04572b098cf3aa70f8520",
        "project_id": "1bbb39e66e614bbc831346bb1c15babb",
        "environment_id": "6175ea4cb70b4d08add43ebfa6a30004",
        "created_at": "2023-11-16T08:30:46+00:00",
        "updated_at": "2023-11-16T08:30:46+00:00",
        "subject_details": {
            "key": "documents",
            "tenant": "default",
            "resource": "Folder",
            "attributes": {}
        },
        "relation_details": {
            "key": "parent",
            "name": "parent",
            "description": "Relation expresses possible 'parent' relation between subject of type 'Folder' to object of type 'File'"
        },
        "object_details": {
            "key": "my_pdf",
            "tenant": "default",
            "resource": "File",
            "attributes": {}
        },
        "tenant_details": {
            "key": "default",
            "name": "Default Tenant",
            "description": null,
            "attributes": null
        }
    }
]
Filter
filter the relationship tuples data
Filter by subject
accepts either the resource instance id or resource_type:resource_instance
in this example Folder:documents
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?subject=Folder:documents&page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
Filter by object
accepts either the resource instance id or resource_type:resource_instance
in this example File:my_pdf
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?object=File:my_pdf&page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
Filter by relation
accepts either the relation id or key
in this example parent or 9c6aee683f5c482cabd2d536734801c9
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?relation=parent&page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
Filter by object_type
accepts either the resource id or key
in this example File or 3bdd97e40010426bbf0648d962779122
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?object_type=File&page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
Filter by subject_type
accepts either the resource id or key
in this example Folder or 6e6855d2b2cf438c9bf79136ec72c188
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?subject_type=Folder&page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
Filter by tenant
The tenant key or id to filter by
in this example default
curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/relationship_tuples?tenant=default&page=1&per_page=10' \
  -H 'authorization: Bearer API_SECRET_KEY'
this is equivalent to logical AND between them