Skip to main content
Version: 2.0.0

Node.js Bulk Requests Examples

1. Bulk Create Relationship Tuples

The bulk request will creates multiple relationship tuples at once using the provided tuple data. The bulk request is a POST request to the /relationship_tuples/bulk endpoint. In the data of the request, each tuple object in the operations array is of type RelationshipTupleCreate and is essentially a tuple of (subject, relation, object, tenant).

  • subject and object are both resource instances, formatted as <resource_type:instance_key> strings (e.g: Folder:budget23).
  • relation is the name of the relation.
  • tenant is the key of the tenant in which to place the relation (optional if at least one of subject/object already exists).
curl 'https://api.permit.io/v2/facts/{proj_id}/{env_id}/relationship_tuples/bulk' \
-H 'authorization: Bearer API_SECRET_KEY'
-D '{ "operations":[
{
"subject": "organization:permitio",
"relation": "owner",
"object": "repo:opal",
"tenant": "public"
},
]
}'

The return value is a list of RelationshipTuple objects, one for each tuple that was created.

2. Bulk Delete Relationship Tuples

Deletes multiple relationship tuples at once using the provided tuple data. The bulk request is a DELETE request to the /relationship_tuples/bulk endpoint. Each tuple object is of type RelationshipTupleDelete and is essentially a tuple of (subject, relation, object).

  • subject and object are both resource instances, formatted as <resource_type:instance_key> strings (e.g: Folder:budget23).
  • relation is the name of the relation.
curl 'https://api.permit.io/v2/facts/{proj_id}/{env_id}/relationship_tuples/bulk' \
-H 'authorization: Bearer API_SECRET_KEY'
-D '{ "idents": [
{
"subject": "organization:permitio",
"relation": "owner",
"object": "repo:removed_repo"
}
]
}'

3. Bulk Create Users

The bulk request creates multiple users at once using the provided user data. The bulk request is a POST request to the /bulk/users endpoint. In the data of the request, each user object in the users array is of type UserCreate and contains the user's details such as username, email, password, etc.

curl -X POST \
'https://api.permit.io/v2/facts/{proj_id}/{env_id}/bulk/users' \
-H 'authorization: Bearer API_SECRET_KEY' \
-D '{
"users": [
{
"username": "user1",
"email": "user1@example.com",
"password": "password1"
},
{
"username": "user2",
"email": "user2@example.com",
"password": "password2"
}
]
}'

4. Bulk Replace Users

The bulk request replaces multiple users at once using the provided user data, allowing you to change users' data (e.g., email, first name), except for the key value. The bulk request is a PUT request to the /bulk/users endpoint. In the data of the request, each user object in the users array is of type UserCreate and contains the user's details such as username, email, password, etc.


curl -X PUT \
'https://api.permit.io/v2/facts/{proj_id}/{env_id}/bulk/users' \
-H 'authorization: Bearer API_SECRET_KEY' \
-D '{
"users": [
{
"username": "user1",
"email": "user1@example.com",
"password": "password1"
},
{
"username": "user2",
"email": "user2@example.com",
"password": "password2"
}
]
}'

5. Bulk Delete Users

The bulk request deletes multiple users at once using the provided user data. The bulk request is a DELETE request to the /bulk/users endpoint. In the data of the request, every 'string' value in the idents array represents a user to delete.


curl -X DELETE \
'https://api.permit.io/v2/facts/{proj_id}/{env_id}/bulk/users' \
-H 'authorization: Bearer API_SECRET_KEY' \
-D '{
"idents": [
"user1",
"user2"
]
}'

6. Possible Errors:

  • PermitApiError: If the API returns an error HTTP status code.
  • PermitContextError: If the configured ApiContext does not match the required endpoint context.