Reten Docs

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

HeaderRequiredValue
AuthorizationYesBearer <access_token>
x-tenant-idYesUUID of a tenant the calling user belongs to — not the new one, which does not exist yet

Request Body

FieldTypeRequiredDescription
tenantNamestringYesTenant name, unique (maximum 255 characters)
tenantSlugstringYesTenant slug, unique (maximum 255 characters): lowercase letters and digits, in groups separated by single hyphens (acme-corp)
tenantContactEmailstringNoTenant contact email
tenantContactPhonestringNoTenant contact phone (maximum 50 characters)
adminFirstNamestringYesAdmin first name (maximum 255 characters)
adminLastNamestringYesAdmin last name (maximum 255 characters)
adminUsernamestringYesAdmin username, unique (maximum 100 characters)
adminEmailstringYesAdmin email, unique
adminPasswordstringYesAdmin 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:

  1. Checks that the tenant name, the slug, the admin email and the admin username are not taken, and that the platform has the admin role. If a value is taken, it responds 409; if the role is missing, 400. In both cases it creates nothing.
  2. Creates the tenant's database schema and runs the tenant migrations on it, as a single step; the migrations also create the main project General with its root audience. If it fails, it responds 500 and creates nothing: the same request can be sent again.
  3. Creates the tenant, the admin user with the admin role, and the memberships of the admin and of the calling user in the new tenant, in a single transaction. If it fails, it responds 500 and the tenant is not created: the same request can be sent again.
  4. 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 responds 500, but the tenant and its admin already exist, without those catalogs or with only part of them: sending the same request again responds 409, because the name, the slug, the email and the username are taken.

Error Responses

StatusDescription
400Validation error — a field is missing or invalid, or an unknown field is sent
400Missing x-tenant-id — Missing required header: x-tenant-id
400The platform has no admin role — ADMIN role not found. Please run the seed script first.
401Missing or invalid access token
403The calling user does not belong to the tenant in x-tenant-id — User does not have access to the requested tenant
403Missing permission — Required permissions: tenant:create
409Tenant name already exists
409Tenant slug already exists
409Email already in use
409Username already in use
500Creating the schema, the transaction or the seeding failed; what each failure leaves behind is under "What happens on setup"