Skip to main content

PUT /api/users/{user_id} · PATCH /api/users/{user_id}

Updates a user’s profile. Both PUT and PATCH methods are accepted — only the fields present in the request body are changed. Permission rules:
  • A non-admin user may only update their own record (user_id must match the token’s user). Attempts to update another user’s record return 403.
  • Non-admin users may change first_name, last_name, email, and username. Any role or is_active field in the request body is silently stripped before processing.
  • Administrators may update any user, including changing their role and is_active status.

Authentication

Requires a valid Bearer access token.
Authorization: Bearer <access_token>

Path Parameters

user_id
integer
required
The ID of the user to update.

Request Body

first_name
string
Updated first name for the user.
last_name
string
Updated last name for the user.
email
string
Updated email address. Must be a valid unique email format. Stored in lowercase.
username
string
Updated username. Must be 3–80 characters, letters/digits/underscores/hyphens only, and unique.
is_active
boolean
Activate or deactivate the user account. Admin only — this field is ignored for non-admin requests.
role
string
Assign a new role to the user. Admin only — this field is ignored for non-admin requests. Allowed values: admin, user.

Response

success
boolean
true when the update succeeds.
message
string
Human-readable confirmation message.
data
object
The updated user object.

Errors

StatusDescription
400No data provided, or an invalid role value was supplied.
401Missing or invalid access token.
403The authenticated user is not an admin and is requesting to update another user.
404No user exists with the given user_id.

Examples

Non-admin — update own profile

curl -X PUT "https://task-forge-gbd6h8gtg8hchve9.chilecentral-01.azurewebsites.net/api/users/42" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "Jane",
    "last_name": "Doe"
  }'

Admin — update any user and change role

curl -X PUT "https://task-forge-gbd6h8gtg8hchve9.chilecentral-01.azurewebsites.net/api/users/42" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "Jane",
    "last_name": "Doe",
    "role": "admin",
    "is_active": true
  }'
{
  "success": true,
  "message": "Usuario actualizado con exito",
  "data": {
    "id": 42,
    "username": "jdoe",
    "email": "jdoe@example.com",
    "first_name": "Jane",
    "last_name": "Doe",
    "full_name": "Jane Doe",
    "is_active": true,
    "role": {
      "id": 1,
      "name": "admin",
      "description": "Administrator"
    },
    "created_at": "2024-01-15T10:30:00",
    "updated_at": "2024-03-17T14:00:00"
  }
}

Build docs developers (and LLMs) love