Skip to main content
PATCH
/
api
/
admin
/
users
/
{id}
/
status
Toggle User Status
curl --request PATCH \
  --url https://api.example.com/api/admin/users/{id}/status \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "isActive": true,
  "isSuspended": true,
  "suspensionReason": "<string>"
}
'

Overview

Activate, deactivate, or suspend a user account. This endpoint allows administrators to manage user account status and access.

Authentication

Authorization
string
required
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

id
integer
required
The unique identifier of the user whose status to change

Request Body

isActive
boolean
Set to true to activate the account, false to deactivate it
isSuspended
boolean
Set to true to suspend the account, false to unsuspend it
suspensionReason
string
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"
}

Build docs developers (and LLMs) love