X Enterprises
fastify-xadmin

Tenants Routes

Admin REST endpoints for listing and creating tenants — GET /api/admin/tenants, POST /api/admin/tenants.

Tenants Routes

Endpoints for listing all tenants and creating new ones. Tenants represent isolated organisations or workspaces within a multi-tenant deployment.

Routes

GET   /api/admin/tenants   List all tenants
POST  /api/admin/tenants   Create a new tenant

GET /api/admin/tenants

Return all tenants with basic metadata.

Usage

const response = await fetch("/api/admin/tenants?page=1&limit=20", {
  headers: { Authorization: `Bearer ${adminToken}` },
});
const { tenants, total } = await response.json();

Query Parameters

NameTypeDefaultDescription
pagenumber1Page number (1-indexed).
limitnumber20Results per page.
searchstringFilter by tenant name or slug.

Response

{
  "tenants": [
    {
      "id": "tnt_abc",
      "slug": "acme-corp",
      "name": "Acme Corp",
      "userCount": 12,
      "createdAt": "2025-01-15T09:00:00.000Z"
    }
  ],
  "total": 5,
  "page": 1,
  "limit": 20
}

POST /api/admin/tenants

Create a new tenant organisation.

Usage

const response = await fetch("/api/admin/tenants", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${adminToken}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    slug: "globex",
    name: "Globex Corporation",
  }),
});
const tenant = await response.json();

Body Fields

FieldTypeRequiredDescription
slugstringYesURL-safe unique identifier (e.g., "globex").
namestringYesDisplay name for the tenant.

Response

{
  "id": "tnt_xyz",
  "slug": "globex",
  "name": "Globex Corporation",
  "userCount": 0,
  "createdAt": "2025-04-19T10:00:00.000Z"
}

AI Context

package: "@xenterprises/fastify-xadmin"
routes:
  - GET /api/admin/tenants — paginated tenant list with optional name/slug search
  - POST /api/admin/tenants — create tenant; slug must be unique
auth: all routes require the admin role set at plugin registration

See Also

  • Users Routes — filter users by tenantId or move a user to a different tenant
  • Audit Log — tenant creation events appear in the audit log
Copyright © 2026