Skip to main content
PUT
/
api
/
users
/
{id}
Update User
curl --request PUT \
  --url https://api.example.com/api/users/{id} \
  --header 'Content-Type: application/json' \
  --data '
{
  "username": "<string>",
  "email": "<string>",
  "password_hash": "<string>",
  "firstname": "<string>",
  "lastname": "<string>",
  "phone_number": "<string>",
  "role": "<string>",
  "is_active": true,
  "profileImage": "<string>"
}
'
{
  "404": {},
  "id": 123,
  "username": "<string>",
  "email": "<string>",
  "password_hash": "<string>",
  "firstname": "<string>",
  "lastname": "<string>",
  "phone_number": "<string>",
  "role": "<string>",
  "is_active": true,
  "profileImage": "<string>",
  "created_at": {},
  "updated_at": {}
}

Overview

This endpoint updates an existing user’s information. The password is automatically hashed using BCrypt encryption if provided.

Request

id
long
required
The unique identifier of the user to update
username
string
Updated username for the user
email
string
Updated email address
password_hash
string
New password in plain text (will be encrypted automatically)
firstname
string
Updated first name
lastname
string
Updated last name
phone_number
string
Updated phone number
role
string
Updated role (e.g., ADMIN, USER, DRIVER)
is_active
boolean
Updated active status
profileImage
string
Updated profile image URL or path
curl -X PUT 'http://localhost:8080/api/users/1' \
  -H 'Content-Type: application/json' \
  -d '{
    "username": "johndoe_updated",
    "email": "[email protected]",
    "password_hash": "newSecurePassword456",
    "firstname": "John",
    "lastname": "Doe",
    "phone_number": "+1234567890",
    "role": "ADMIN",
    "is_active": true,
    "profileImage": "/images/profiles/johndoe_new.jpg"
  }'

Response

id
long
Unique identifier of the updated user
username
string
User’s updated username
email
string
User’s updated email address
password_hash
string
Encrypted password hash
firstname
string
User’s updated first name
lastname
string
User’s updated last name
phone_number
string
User’s updated phone number
role
string
User’s updated role
is_active
boolean
Updated active status
profileImage
string
Updated profile image URL or path
created_at
timestamp
Original creation timestamp
updated_at
timestamp
Timestamp of the last update

Example Response

{
  "id": 1,
  "username": "johndoe_updated",
  "email": "[email protected]",
  "password_hash": "$2a$10$X7qp9uZOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy",
  "firstname": "John",
  "lastname": "Doe",
  "phone_number": "+1234567890",
  "role": "ADMIN",
  "is_active": true,
  "profileImage": "/images/profiles/johndoe_new.jpg",
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-26T16:45:00Z"
}

Error Responses

404
error
User not found - returned when no user exists with the specified ID

Notes

  • The user must exist before it can be updated
  • The id in the request body is overridden with the path parameter to ensure consistency
  • Passwords are automatically hashed using BCrypt encryption
  • Send the password in plain text in the password_hash field - the server handles encryption

Build docs developers (and LLMs) love