Skip to main content

Users API

Base URL: /api/users

The Users API handles user listing, profile management, role changes, and user removal with full RBAC (Role-Based Access Control) enforcement.


Roles and Permissions

RoleView UsersView DetailsChange RolesRemove Users
admin
developer
viewer

GET /api/users

List all users in the organization.

Authentication: Required (All roles)

Response (200 OK)

{
"success": true,
"users": [
{
"id": "507f1f77bcf86cd799439011",
"email": "admin@example.com",
"name": "John Admin",
"role": "admin",
"status": "active",
"lastLoginAt": "2026-02-09T10:30:00.000Z",
"createdAt": "2026-01-15T08:00:00.000Z"
},
{
"id": "507f1f77bcf86cd799439012",
"email": "dev@example.com",
"name": "Jane Developer",
"role": "developer",
"status": "active",
"lastLoginAt": "2026-02-08T14:20:00.000Z",
"createdAt": "2026-01-20T09:00:00.000Z"
}
]
}

User Status Values

StatusDescription
activeNormal active user
suspendedAccount suspended by admin
pendingAwaiting email verification

GET /api/users/:id

Get detailed information about a specific user.

Authentication: Required (All roles)

Parameters

ParameterTypeDescription
idstringUser ID (MongoDB ObjectId)

Response (200 OK)

{
"success": true,
"user": {
"id": "507f1f77bcf86cd799439011",
"email": "admin@example.com",
"name": "John Admin",
"role": "admin",
"status": "active",
"lastLoginAt": "2026-02-09T10:30:00.000Z",
"createdAt": "2026-01-15T08:00:00.000Z",
"updatedAt": "2026-02-08T16:00:00.000Z"
}
}

Error Responses

StatusErrorDescription
400Invalid user ID formatID is not a valid ObjectId
401Authentication requiredNo valid JWT token
404User not foundUser doesn't exist or belongs to different org
500Failed to fetch userInternal server error

Note: For security (tenant isolation), users from other organizations return 404, not 403.


PATCH /api/users/:id/role

Change a user's role.

Authentication: Required
Authorization: Admin role only

Parameters

ParameterTypeDescription
idstringUser ID (MongoDB ObjectId)

Request Body

{
"role": "developer"
}
FieldTypeRequiredValues
rolestringYesadmin, developer, viewer

Response (200 OK)

{
"success": true,
"message": "User role updated to developer",
"user": {
"id": "507f1f77bcf86cd799439011",
"email": "user@example.com",
"name": "Jane User",
"role": "developer"
}
}

Business Rules

  1. Cannot change own role: Admins cannot demote themselves
  2. Last admin protection: Cannot demote the last admin to a lower role

Error Responses

StatusErrorDescription
400Missing required fieldRole not provided
400Invalid roleRole not admin/developer/viewer
400Invalid user ID formatInvalid ObjectId
401Authentication requiredNo valid JWT token
403ForbiddenCaller is not an admin
403Cannot change own roleTried to change own role
403Cannot remove last adminWould leave org without admin
404User not foundUser doesn't exist or different org
500Failed to update roleInternal server error

Audit Logging

Role changes are logged to audit_logs:

{
"action": "user.role_changed",
"targetType": "user",
"targetId": "507f1f77bcf86cd799439011",
"details": {
"oldRole": "viewer",
"newRole": "developer",
"targetEmail": "user@example.com"
}
}

DELETE /api/users/:id

Remove a user from the organization.

Authentication: Required
Authorization: Admin role only

Parameters

ParameterTypeDescription
idstringUser ID (MongoDB ObjectId)

Response (200 OK)

{
"success": true,
"message": "User user@example.com has been removed from the organization"
}

Business Rules

  1. Cannot delete self: Admins cannot remove their own account
  2. Last admin protection: Cannot delete the last admin
  3. Data retention: User's executions and data remain for audit trail

Error Responses

StatusErrorDescription
400Invalid user ID formatInvalid ObjectId
401Authentication requiredNo valid JWT token
403ForbiddenCaller is not an admin
403Cannot delete yourselfTried to delete own account
403Cannot delete last adminWould leave org without admin
404User not foundUser doesn't exist or different org
500Failed to remove userInternal server error

Audit Logging

User removals are logged to audit_logs:

{
"action": "user.removed",
"targetType": "user",
"targetId": "507f1f77bcf86cd799439011",
"details": {
"targetEmail": "user@example.com",
"targetRole": "developer",
"targetName": "Jane User"
}
}

Important: When a user is removed, their historical data (test runs, executions) remains in the system for audit and reporting purposes.


Example Usage

List Organization Members

curl -X GET https://api.automation.keinar.com/api/users \
-H "Authorization: Bearer <jwt-token>"

Get User Details

curl -X GET https://api.automation.keinar.com/api/users/507f1f77bcf86cd799439011 \
-H "Authorization: Bearer <jwt-token>"

Change User Role

curl -X PATCH https://api.automation.keinar.com/api/users/507f1f77bcf86cd799439011/role \
-H "Authorization: Bearer <jwt-token>" \
-H "Content-Type: application/json" \
-d '{"role": "admin"}'

Remove User

curl -X DELETE https://api.automation.keinar.com/api/users/507f1f77bcf86cd799439011 \
-H "Authorization: Bearer <jwt-token>"

Rate Limiting

EndpointLimitWindow
Role change / Delete5 requests1 minute
List / Get details100 requests1 minute