curl --request PUT \
--url https://api.example.com/api/users/{id} \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"password": "<string>",
"role": {},
"status": {},
"phone": "<string>",
"address": "<string>",
"city": "<string>",
"country": "<string>",
"postal_code": "<string>",
"gender": "<string>",
"birth_date": "<string>",
"document_type": {},
"document_number": "<string>",
"avatar": "<string>",
"refresh_token": {}
}
'{
"user_id": "<string>",
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"phone": "<string>",
"address": "<string>",
"city": "<string>",
"country": "<string>",
"postal_code": "<string>",
"gender": "<string>",
"birth_date": "<string>",
"role": {},
"status": {},
"avatar": "<string>",
"document_type": {},
"document_number": "<string>",
"refresh_token": {},
"created_at": "<string>",
"updated_at": "<string>"
}Update an existing user in the system
curl --request PUT \
--url https://api.example.com/api/users/{id} \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"password": "<string>",
"role": {},
"status": {},
"phone": "<string>",
"address": "<string>",
"city": "<string>",
"country": "<string>",
"postal_code": "<string>",
"gender": "<string>",
"birth_date": "<string>",
"document_type": {},
"document_number": "<string>",
"avatar": "<string>",
"refresh_token": {}
}
'{
"user_id": "<string>",
"email": "<string>",
"name": "<string>",
"surname": "<string>",
"phone": "<string>",
"address": "<string>",
"city": "<string>",
"country": "<string>",
"postal_code": "<string>",
"gender": "<string>",
"birth_date": "<string>",
"role": {},
"status": {},
"avatar": "<string>",
"document_type": {},
"document_number": "<string>",
"refresh_token": {},
"created_at": "<string>",
"updated_at": "<string>"
}Authorization: Bearer <token>auth_token=<token>ADMIN role to update users, or users should only be able to update their own profile.
user_id field.ADMIN: Administrator with full accessUSER: Regular user with limited accessON: Active accountOFF: Inactive/disabled accountDNI: National Identity Document (Spain)PASSPORT: PassportNIE: Foreign Identity Number (Spain)curl -X PUT https://your-domain.com/api/users/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"phone": "+34677889900"
}'
curl -X PUT https://your-domain.com/api/users/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{
"password": "NewSecurePassword456!"
}'
curl -X PUT https://your-domain.com/api/users/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{
"status": "OFF"
}'
curl -X PUT https://your-domain.com/api/users/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{
"name": "María Carmen",
"address": "Calle Nueva 456",
"city": "Sevilla",
"postal_code": "41001"
}'
ADMIN or USER)ON or OFF){
"user_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"email": "[email protected]",
"name": "María Carmen",
"surname": "García",
"phone": "+34677889900",
"address": "Calle Nueva 456",
"city": "Sevilla",
"country": "España",
"postal_code": "41001",
"gender": "Femenino",
"birth_date": "1990-05-15T00:00:00.000Z",
"role": "USER",
"status": "ON",
"avatar": "https://ui-avatars.com/api/?name=María&background=random",
"document_type": "DNI",
"document_number": "12345678A",
"refresh_token": null,
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-03-05T14:22:00.000Z"
}
{
"statusCode": 400,
"statusMessage": "ID requerido"
}
{
"statusCode": 401,
"statusMessage": "Unauthorized: Token is missing or invalid"
}
{
"statusCode": 500,
"statusMessage": "Error al actualizar usuario"
}
if (updateData.password) {
updateData.password = await bcrypt.hash(updateData.password, 10)
}
birth_date is included, it’s converted to a JavaScript Date object:
if (updateData.birth_date) {
updateData.birth_date = new Date(updateData.birth_date)
}
updated_at field is automatically updated by Prisma using the @updatedAt directive in the schema. You don’t need to include it in your request.
update method.