Skip to main content

Create Tenant

Tenants are used to group users and roles together. A user can have different roles in multiple tenants. The most common use case for using tenants is organization or company.

Create Tenant​

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}/tenants' \
-H 'authorization: Bearer API_SECRET_KEY'
--data-raw '{"key":"new-tenant-name","name":"New Tenant Name","description":"New tenant description"}' \

The return user object will look like this:

{
"key": "new-tenant-name",
"id": "1e17ad4486cb4320bba067b2f19exxxx",
"organization_id": "903ebc2765b848289d6dfbd3c21exxxx",
"project_id": "3c4244c7bcab4c97990e5bc724daxxxx",
"environment_id": "9ba956da646948538efaee4cf10dxxxx",
"created_at": "2023-07-31T08:16:03+00:00",
"updated_at": "2023-07-31T08:16:03+00:00",
"last_action_at": "2023-07-31T08:16:03+00:00",
"name": "New Tenant Name",
"description": "New tenant description",
"attributes": null
}

Get all tenants​

Note the search query parameter in the following command.

curl 'https://api.permit.io/v2/facts/{project_id}/{env_id}/tenants?search=default&include_total_count=true&page=1&per_page=100' \
-H 'authorization: Bearer API_SECRET_KEY'

The return user object will look like this:

{
"data": [
{
"key": "default",
"id": "5620130cc6a74ada9f0c194cab20a53e",
"organization_id": "903ebc2765b848289d6dfbd3c21exxxx",
"project_id": "3c4244c7bcab4c97990e5bc724daxxxx",
"environment_id": "9ba956da646948538efaee4cf10dxxxx",
"created_at": "2023-02-28T10:07:44+00:00",
"updated_at": "2023-02-28T10:07:44+00:00",
"last_action_at": "2023-02-28T10:07:44+00:00",
"name": "Default Tenant",
"description": null,
"attributes": null
}
],
"total_count": 1,
"page_count": 1
}```