Setup Tenant
Create a new tenant with its own database schema and an admin user.
POST /api/tenant/setup
Create a new tenant with its own database schema, its default catalogs and an admin user. The calling user also becomes a member of the new tenant. The calling user's current access token does not include the new tenant: to work in it, get a new one with Refresh Token or by logging in again.
Auth: Required — tenant:create permission
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer <access_token> |
x-tenant-id | Yes | UUID of a tenant the calling user belongs to — not the new one, which does not exist yet |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
tenantName | string | Yes | Tenant name, unique (maximum 255 characters) |
tenantSlug | string | Yes | Tenant slug, unique (maximum 255 characters): lowercase letters and digits, in groups separated by single hyphens (acme-corp) |
tenantContactEmail | string | No | Tenant contact email |
tenantContactPhone | string | No | Tenant contact phone (maximum 50 characters) |
adminFirstName | string | Yes | Admin first name (maximum 255 characters) |
adminLastName | string | Yes | Admin last name (maximum 255 characters) |
adminUsername | string | Yes | Admin username, unique (maximum 100 characters) |
adminEmail | string | Yes | Admin email, unique |
adminPassword | string | Yes | Admin password (8 to 100 characters) |
The admin is always a new user: an email or username that already exists responds 409.
Example
curl -X POST https://api.reten.ai/api/tenant/setup \
-H "Authorization: Bearer <token>" \
-H "x-tenant-id: <tenant-id>" \
-H "Content-Type: application/json" \
-d '{
"tenantName": "Acme Corp",
"tenantSlug": "acme-corp",
"tenantContactEmail": "contact@acme.com",
"tenantContactPhone": "+56 9 1234 5678",
"adminFirstName": "Acme",
"adminLastName": "Admin",
"adminUsername": "acme-admin",
"adminEmail": "admin@acme.com",
"adminPassword": "SecurePass123!"
}'const response = await fetch("https://api.reten.ai/api/tenant/setup", {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"x-tenant-id": "<tenant-id>",
"Content-Type": "application/json",
},
body: JSON.stringify({
tenantName: "Acme Corp",
tenantSlug: "acme-corp",
tenantContactEmail: "contact@acme.com",
tenantContactPhone: "+56 9 1234 5678",
adminFirstName: "Acme",
adminLastName: "Admin",
adminUsername: "acme-admin",
adminEmail: "admin@acme.com",
adminPassword: "SecurePass123!",
}),
});
const { tenant, adminUser } = await response.json();import requests
response = requests.post(
"https://api.reten.ai/api/tenant/setup",
headers={
"Authorization": "Bearer <token>",
"x-tenant-id": "<tenant-id>",
},
json={
"tenantName": "Acme Corp",
"tenantSlug": "acme-corp",
"tenantContactEmail": "contact@acme.com",
"tenantContactPhone": "+56 9 1234 5678",
"adminFirstName": "Acme",
"adminLastName": "Admin",
"adminUsername": "acme-admin",
"adminEmail": "admin@acme.com",
"adminPassword": "SecurePass123!",
},
)
body = response.json()Response 201 Created
{
"tenant": {
"id": "660e8400-e29b-41d4-a716-446655440000",
"name": "Acme Corp",
"slug": "acme-corp",
"contactEmail": "contact@acme.com",
"contactPhone": "+56 9 1234 5678"
},
"adminUser": {
"id": "770e8400-e29b-41d4-a716-446655440000",
"firstName": "Acme",
"lastName": "Admin",
"username": "acme-admin",
"email": "admin@acme.com"
}
}contactEmail and contactPhone are always present: null when the request does not send them.
What happens on setup
The steps run in this order, and each failure leaves a different state behind:
- Checks that the tenant name, the slug, the admin email and the admin username are not taken, and that the platform has the
adminrole. If a value is taken, it responds409; if the role is missing,400. In both cases it creates nothing. - Creates the tenant's database schema and runs the tenant migrations on it, as a single step; the migrations also create the main project
Generalwith its root audience. If it fails, it responds500and creates nothing: the same request can be sent again. - Creates the tenant, the admin user with the
adminrole, and the memberships of the admin and of the calling user in the new tenant, in a single transaction. If it fails, it responds500and the tenant is not created: the same request can be sent again. - Seeds the tenant's three activity-config catalogs from the backend default constants:
user_retention_status_configs(the 12 retention status defaults), activity-reason configs, and task-result-type configs. It then creates the tenant's ten default activity forms, one per intent category. If it fails, it responds500, but the tenant and its admin already exist, without those catalogs or with only part of them: sending the same request again responds409, because the name, the slug, the email and the username are taken.
Error Responses
| Status | Description |
|---|---|
400 | Validation error — a field is missing or invalid, or an unknown field is sent |
400 | Missing x-tenant-id — Missing required header: x-tenant-id |
400 | The platform has no admin role — ADMIN role not found. Please run the seed script first. |
401 | Missing or invalid access token |
403 | The calling user does not belong to the tenant in x-tenant-id — User does not have access to the requested tenant |
403 | Missing permission — Required permissions: tenant:create |
409 | Tenant name already exists |
409 | Tenant slug already exists |
409 | Email already in use |
409 | Username already in use |
500 | Creating the schema, the transaction or the seeding failed; what each failure leaves behind is under "What happens on setup" |