RealTimeX
Start For Free

RealTimeX

API Documentation

IntroductionAuthenticationBase URLHeadersError codes
CreateListGet by IDUpdateDelete
Sample requestsSample responsesStatus codesAppendixChangelog

API Reference

Create Custom Role

Overview

Create a custom role for your tenant in the client Platform. Custom roles let you define named permission sets (for example Sales Manager) beyond the built-in system roles such as Admin and User.

Each role has a stable slug (used when assigning users), a human-readable name, optional description, permission keys, and optional metadata (for example a badge color in the Platform UI).

When to use this endpoint?

Use Create Custom Role when:

  • An admin adds a new role from Platform → Custom Roles.
  • You need department- or desk-specific permission sets (sales, support, and so on).
  • You want a reusable slug to assign via Platform → Users → Update.
  • You store UI hints (color, icon) in metadata for the roles table.

Part of the client Platform Custom Roles module. Requires a client Access Token with tenant admin privileges — not a chat end-user token.

Workflow

  1. 1

    Define the role

    In the Platform Custom Roles screen, choose a display name, unique slug, description, and permission keys.

  2. 2

    Create the role

    POST the payload with tenant headers and a client Access Token. The API returns the new role document.

  3. 3

    Save the slug

    Use data.slug when assigning roles to users (Platform → Users → Update uses the role slug).

  4. 4

    Assign to users

    Update tenant users with the new slug so they receive the intended permissions in your product.

Request Fields

FieldTypeRequiredDescription
namestringRequiredDisplay name shown in the Platform UI (for example Sales Manager).
slugstringRequiredUnique machine-friendly id (for example sales-manager). Used when assigning the role to users. Prefer lowercase kebab-case.
descriptionstringOptionalShort explanation of what this role is for.
permissionsstring[]OptionalPermission keys granted by this role (for example chat.read, chat.assign).
metadataobjectOptionalExtra attributes for your Platform UI (color, labels, and so on).
POST{baseUrl}/api/{apiVersion}/user-role/create

Authentication

Required (Bearer token)

Tenant-scoped

Yes (tenant DB — requires x-client-id)

Request Headers

HeaderValueDescription
AuthorizationBearer <access_token>Client Access Token with tenant admin privileges (Platform panel).
is-tenanttrueTargets the tenant DB ("true", needs x-client-id).
x-client-id{{clientId}}Tenant (client) id. Required when is-tenant=true.
Content-Typeapplication/jsonJSON request body.

Request Payload

Example creating a Sales Manager role with two permission keys and a UI color in metadata:

json
{
  "name": "Sales Manager",
  "slug": "sales-manager",
  "description": "Manages the sales desk",
  "permissions": [
    "chat.read",
    "chat.assign"
  ],
  "metadata": {
    "color": "#3b82f6"
  }
}

Success Response (HTTP 201 Created)

On success, the API returns the created role. isSystem and isDefault are typically false for custom roles.

json
{
  "success": true,
  "message": "Role created successfully",
  "data": {
    "_id": "66b0...c9d0",
    "name": "Sales Manager",
    "slug": "sales-manager",
    "description": "Manages the sales desk",
    "permissions": [
      "chat.read",
      "chat.assign"
    ],
    "isDefault": false,
    "isSystem": false,
    "metadata": {
      "color": "#3b82f6"
    },
    "createdAt": "2026-06-23T10:00:00.000Z",
    "updatedAt": "2026-06-23T10:00:00.000Z"
  },
  "error": null
}

Common Errors

Create fails when the token lacks admin access, the slug already exists, or required fields are missing.

HTTP 401 Unauthorized — No token

json
{
  "success": false,
  "message": "No token, authorization denied",
  "data": null,
  "error": "Unauthorized"
}

HTTP 403 Forbidden — Tenant admin required

json
{
  "success": false,
  "message": "Access denied: tenant admin privileges required",
  "data": null,
  "error": null
}

HTTP 400 Bad Request — Duplicate slug

json
{
  "success": false,
  "message": "Role slug already exists",
  "data": null,
  "error": "Role slug already exists"
}
CodeReason
401 UnauthorizedAccess Token is missing, invalid, or expired.
403 ForbiddenTenant admin privileges required for Platform Custom Roles.
400 Bad RequestMissing name / slug, or slug already exists.
500 Internal Server ErrorAn unexpected error occurred while creating the role.

Best Practices

  • Keep slugs stable after create — users are assigned by slug, and update does not change it.
  • Use clear permission keys your product already understands; empty permissions means no extra grants beyond defaults.
  • Prefer kebab-case slugs (sales-manager) so they match user update payloads.
  • Always send tenant headers with a client Bearer token over HTTPS.

Role created

Open the role in your Custom Roles list, then assign slug to users under Platform → Users → Update.

PreviousBlock / unblockNextList

On this page

OverviewWhen to use this endpoint?WorkflowRequest FieldsRequest HeadersRequest PayloadSuccess ResponseCommon ErrorsBest Practices