Change User Company Role API
Overview
Endpoint used by Company Admins or Super Admins to dynamically update or reassign a user's B2B company role (COMPANY_ADMIN, COMPANY_MANAGER, or COMPANY_EMPLOYEE) within a corporate tenant. This allows changing any user to a manager or admin, or back to an employee.
- Endpoint:
/api/users/change-company-role - Method:
PATCH/POST - Access: Company Admin / Super Admin
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
userId | String (UUID) | Yes | Target user ID |
companyId | String (UUID) | Yes | Target B2B company ID |
role | Enum | Yes | Target company role: COMPANY_ADMIN, COMPANY_MANAGER, or COMPANY_EMPLOYEE |
Request Body Example
{
"userId": "123e4567-e89b-12d3-a456-426614174003",
"companyId": "123e4567-e89b-12d3-a456-426614174000",
"role": "COMPANY_MANAGER"
}
Success Response (200 OK)
{
"success": true,
"message": "User role in company updated to 'COMPANY_MANAGER' successfully",
"data": {
"id": "123e4567-e89b-12d3-a456-426614174003",
"email": "employee@acme.com",
"firstName": "John",
"lastName": "Doe",
"phone": "+919876543210",
"clientType": "B2B",
"companyId": "123e4567-e89b-12d3-a456-426614174000",
"companyRole": "COMPANY_MANAGER",
"roles": [
"COMPANY_MANAGER"
],
"company": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "Acme Corp",
"active": true
}
}
}
Error Response (400 / 404)
{
"success": false,
"data": null,
"message": "User does not belong to company ID '123e4567-e89b-12d3-a456-426614174000'"
}
Database Impact
- Tables:
user_role_maps,roles - Operations: Deactivates previous role mappings for the user in the company and creates/activates the new
UserRoleMapentry.