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
metadatafor 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
Define the role
In the Platform Custom Roles screen, choose a display name, unique slug, description, and permission keys.
- 2
Create the role
POST the payload with tenant headers and a client Access Token. The API returns the new role document.
- 3
Save the slug
Use data.slug when assigning roles to users (Platform → Users → Update uses the role slug).
- 4
Assign to users
Update tenant users with the new slug so they receive the intended permissions in your product.
Request Fields
{baseUrl}/api/{apiVersion}/user-role/create- Authentication
- Required (Bearer token)
- Tenant-scoped
- Yes (tenant DB - requires x-client-id)
Request Headers
Request Payload
Example creating a Sales Manager role with two permission keys and a UI color in metadata:
{ "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.
{ "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
{ "success": false, "message": "No token, authorization denied", "data": null, "error": "Unauthorized"}HTTP 403 Forbidden - Tenant admin required
{ "success": false, "message": "Access denied: tenant admin privileges required", "data": null, "error": null}HTTP 400 Bad Request - Duplicate slug
{ "success": false, "message": "Role slug already exists", "data": null, "error": "Role slug already exists"}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.