Overview
Activate, deactivate, or suspend a user account. This endpoint allows administrators to manage user account status and access.
Authentication
Bearer token for authentication. Must be a valid JWT token for a user with ADMIN role.
Authorization
This endpoint requires the ADMIN role.
Path Parameters
The unique identifier of the user whose status to change
Request Body
Set to true to activate the account, false to deactivate it
Set to true to suspend the account, false to unsuspend it
Reason for suspending the account. Required when isSuspended is true.
Response
Returns the updated user object with the new status.
Example Requests
Suspend a User
curl -X PATCH https://api.example.com/api/admin/users/42/status \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"isSuspended": true,
"suspensionReason": "Violation of terms of service"
}'
Activate a User
curl -X PATCH https://api.example.com/api/admin/users/42/status \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"isActive": true,
"isSuspended": false
}'
Example Response
{
"id": 42,
"name": "John Smith",
"email": "[email protected]",
"role": "PATIENT",
"isActive": false,
"isSuspended": true,
"suspensionReason": "Violation of terms of service",
"createdAt": "2024-02-01T14:20:00.000Z",
"updatedAt": "2024-03-03T15:45:00.000Z"
}
Error Responses
404 Not Found
{
"error": "Usuario no encontrado"
}
400 Bad Request
{
"error": "suspensionReason is required when suspending a user"
}
403 Forbidden
{
"error": "Access denied"
}