Skip to main content
PUT
/
api
/
users
/
:id
Update User Profile
curl --request PUT \
  --url https://api.example.com/api/users/:id \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "email": "<string>",
  "password": "<string>"
}
'
{
  "id": 123,
  "name": "<string>",
  "email": "<string>",
  "role": "<string>",
  "isActive": true,
  "isSuspended": true,
  "createdAt": "<string>",
  "updatedAt": "<string>",
  "error": "<string>"
}

Authentication

Requires a valid JWT token in the Authorization header.
Authorization: Bearer <token>

Authorization

Any authenticated user can access this endpoint, but users can only update their own profile. Attempting to update another user’s profile will result in a 403 error.

Path Parameters

id
integer
required
The ID of the user to update. Must match the authenticated user’s ID.

Request Body

name
string
User’s full name. Must be a valid name format.
email
string
User’s email address. Must be a valid email format and unique in the system.
password
string
User’s password. Must be at least 8 characters long.
At least one field must be provided. All fields are optional, but you cannot send an empty request body.

Response

id
integer
The user’s unique identifier
name
string
The user’s updated name
email
string
The user’s updated email address
role
string
The user’s role (ADMIN, DOCTOR, or PATIENT)
isActive
boolean
Whether the user account is active
isSuspended
boolean
Whether the user account is suspended
createdAt
string
ISO 8601 timestamp of when the user was created
updatedAt
string
ISO 8601 timestamp of when the user was last updated
The password field is never returned in the response for security reasons.

Error Responses

error
string
Error message describing what went wrong

Common Errors

Status CodeError MessageDescription
400Invalid user idThe user ID in the path is not a valid number
400Nothing to updateNo valid fields were provided in the request body
400Invalid email formatThe email address format is invalid
400Invalid nameThe name format is invalid
400Password must be at least 8 charactersPassword doesn’t meet minimum length requirement
401Not authenticatedNo valid JWT token was provided
403Access deniedUser attempted to update another user’s profile
409Email already existsThe email address is already in use by another user

Example Request

curl -X PUT https://api.example.com/api/users/42 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Smith",
    "email": "[email protected]"
  }'

Example Response

{
  "id": 42,
  "name": "John Smith",
  "email": "[email protected]",
  "role": "PATIENT",
  "isActive": true,
  "isSuspended": false,
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-03-03T14:22:15.000Z"
}

Build docs developers (and LLMs) love