Skip to main content
PUT
/
api
/
v1
/
users
/
{id}
Update User
curl --request PUT \
  --url https://api.example.com/api/v1/users/{id} \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "firstName": "<string>",
  "lastName": "<string>",
  "role": {},
  "active": true
}
'
{
  "200": {},
  "400": {},
  "404": {},
  "500": {},
  "id": "<string>",
  "username": "<string>",
  "email": "<string>",
  "firstName": "<string>",
  "lastName": "<string>",
  "role": "<string>",
  "createdAt": "<string>",
  "updatedAt": "<string>",
  "active": true
}

Endpoint

PUT /api/v1/users/{id}
Updates an existing user’s information. Note that the username cannot be changed after registration.

Path Parameters

id
UUID
required
Unique user identifier.Example: 0f4df2de-fffb-4a24-9891-381ecf4f0f87

Request Body

email
string
required
User’s email address. Must be a valid email format.Validation:
  • Required
  • Must be a valid email address
Example: jdoe@jdoe.com
firstName
string
required
User’s first name.Validation:
  • Required
  • Max length: 100 characters
Example: Jane
lastName
string
required
User’s last name.Validation:
  • Required
  • Max length: 100 characters
Example: Doe II
role
enum
required
User’s role in the system.Validation:
  • Required
  • Must be one of: ADMIN, USER, GUEST
Example: ADMIN
active
boolean
required
Whether the user account is active.Validation:
  • Required
Example: true

Response

id
UUID
Unique identifier for the user.Example: 0f4df2de-fffb-4a24-9891-381ecf4f0f87
username
string
The user’s username (unchanged).Example: jdoe
email
string
The updated email address.Example: jdoe@jdoe.com
firstName
string
The updated first name.Example: Jane
lastName
string
The updated last name.Example: Doe II
role
string
The updated role.Example: ADMIN
createdAt
string
ISO 8601 timestamp when the user was created (unchanged).Example: 2024-01-15T10:30:00
updatedAt
string
ISO 8601 timestamp when the user was last updated.Example: 2024-01-15T10:35:00
active
boolean
Whether the user account is active.Example: true

Status Codes

200
OK
User updated successfully
400
Bad Request
Validation error - one or more required fields are missing or invalid
404
Not Found
User with the specified ID does not exist
500
Internal Server Error
An unexpected error occurred

Example Request

curl -X PUT http://localhost:8080/api/v1/users/0f4df2de-fffb-4a24-9891-381ecf4f0f87 \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "jdoe@jdoe.com",
    "firstName": "Jane",
    "lastName": "Doe II",
    "role": "ADMIN",
    "active": true
  }'

Example Response

{
  "id": "0f4df2de-fffb-4a24-9891-381ecf4f0f87",
  "username": "jdoe",
  "email": "jdoe@jdoe.com",
  "firstName": "Jane",
  "lastName": "Doe II",
  "role": "ADMIN",
  "createdAt": "2024-01-15T10:30:00",
  "updatedAt": "2024-01-15T10:35:00",
  "active": true
}

Error Response Examples

Validation Error (400)

{
  "type": "about:blank",
  "title": "Validation Failed",
  "status": 400,
  "detail": "email: email must be a valid email address; firstName: first_name is required",
  "timestamp": "2024-01-15T10:30:00"
}

User Not Found (404)

{
  "type": "about:blank",
  "title": "User Not Found",
  "status": 404,
  "detail": "User not found with id: 0f4df2de-fffb-4a24-9891-381ecf4f0f87",
  "userId": "0f4df2de-fffb-4a24-9891-381ecf4f0f87",
  "timestamp": "2024-01-15T10:30:00"
}

Notes

  • The username field is immutable and cannot be changed after user creation
  • The updatedAt timestamp is automatically updated when changes are made
  • Setting active to false deactivates the user account without deleting it

Build docs developers (and LLMs) love