X Enterprises
fastify-xadmin

Roles Routes

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

Roles Routes

Endpoints for listing existing roles and creating new ones. Roles are assigned to users via the Users Routes.

Routes

GET   /api/admin/roles   List all roles
POST  /api/admin/roles   Create a new role

GET /api/admin/roles

Return all defined roles in the system.

Usage

const response = await fetch("/api/admin/roles", {
  headers: { Authorization: `Bearer ${adminToken}` },
});
const { roles } = await response.json();

Response

{
  "roles": [
    { "id": "role_1", "slug": "superadmin", "name": "Super Admin", "createdAt": "2025-01-01T00:00:00.000Z" },
    { "id": "role_2", "slug": "admin",      "name": "Admin",       "createdAt": "2025-01-01T00:00:00.000Z" },
    { "id": "role_3", "slug": "member",     "name": "Member",      "createdAt": "2025-01-01T00:00:00.000Z" }
  ]
}

POST /api/admin/roles

Create a new role that can then be assigned to users.

Usage

const response = await fetch("/api/admin/roles", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${adminToken}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ slug: "billing-manager", name: "Billing Manager" }),
});
const role = await response.json();

Body Fields

FieldTypeRequiredDescription
slugstringYesURL-safe identifier (e.g., "billing-manager"). Must be unique.
namestringYesHuman-readable display name (e.g., "Billing Manager").

Response

{
  "id": "role_4",
  "slug": "billing-manager",
  "name": "Billing Manager",
  "createdAt": "2025-04-01T12:00:00.000Z"
}

AI Context

package: "@xenterprises/fastify-xadmin"
routes:
  - GET /api/admin/roles — returns full list of roles; no pagination
  - POST /api/admin/roles — creates a role; slug must be unique
auth: all routes require the admin role set at plugin registration

See Also

Copyright © 2026