Skip to main content
PUT
/
api
/
clients
/
{id}
Update Client
curl --request PUT \
  --url https://api.example.com/api/clients/{id} \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "name": "<string>",
  "surname": "<string>",
  "phone": "<string>",
  "address": "<string>",
  "city": "<string>",
  "country": "<string>",
  "postal_code": "<string>",
  "gender": "<string>",
  "birth_date": "<string>",
  "document_type": "<string>",
  "document_number": "<string>",
  "status": "<string>"
}
'
{
  "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": "<string>",
  "status": "<string>",
  "avatar": "<string>",
  "document_type": "<string>",
  "document_number": "<string>",
  "created_at": "<string>",
  "updated_at": "<string>"
}

Overview

Updates an existing client’s information. All fields are optional - only include the fields you want to update. The endpoint validates input, checks for email uniqueness, and returns the updated client record.

Authentication

This endpoint requires authentication. Include a valid session token in your request.

Path Parameters

id
string
required
The unique identifier (UUID) of the client to update.

Request Body

All fields are optional. Only include the fields you want to update.
email
string
Client’s email address. Must be unique (not used by another client).Validation: Valid email format, max 50 characters
name
string
Client’s first name.Validation: Minimum 2 characters, max 50 characters
surname
string
Client’s last name.Validation: Minimum 2 characters, max 50 characters
phone
string
Client’s phone number.Validation: Minimum 6 characters, max 20 characters
address
string
Street address.Max length: 255 characters
city
string
City name.Max length: 50 characters
country
string
Country name.Max length: 50 characters
postal_code
string
Postal/ZIP code.Max length: 20 characters
gender
string
Gender identifier.Max length: 10 characters
birth_date
string
Date of birth in ISO 8601 format.Format: ISO 8601 date string (e.g., “1990-05-15”)
document_type
string
Type of identification document.Allowed values: DNI, PASSPORT, NIE
document_number
string
Identification document number.Max length: 20 characters
status
string
Account status.Allowed values: ON, OFF

Response

Returns the updated client object. The password field is excluded from the response for security.
user_id
string
required
Unique identifier for the client (UUID format)
email
string
required
Client’s email address
name
string
required
Client’s first name
surname
string
required
Client’s last name
phone
string
required
Client’s phone number
address
string
required
Street address
city
string
required
City name
country
string
required
Country name
postal_code
string
required
Postal/ZIP code
gender
string
required
Gender identifier
birth_date
string
required
Date of birth in ISO 8601 date format
role
string
required
User role - always USER for clients
status
string
required
Account status (ON or OFF)
avatar
string
required
URL to client’s avatar image
document_type
string
required
Type of identification document
document_number
string
required
Identification document number
created_at
string
required
Timestamp when the client was created
updated_at
string
required
Timestamp when the client was last updated

Example Request

cURL - Update phone and address
curl --request PUT \
  --url 'https://your-domain.com/api/clients/550e8400-e29b-41d4-a716-446655440000' \
  --header 'Content-Type: application/json' \
  --header 'Cookie: your-session-token' \
  --data '{
    "phone": "+34634567890",
    "address": "Calle Nueva 456"
  }'
cURL - Update status
curl --request PUT \
  --url 'https://your-domain.com/api/clients/550e8400-e29b-41d4-a716-446655440000' \
  --header 'Content-Type: application/json' \
  --header 'Cookie: your-session-token' \
  --data '{
    "status": "OFF"
  }'
cURL - Update multiple fields
curl --request PUT \
  --url 'https://your-domain.com/api/clients/550e8400-e29b-41d4-a716-446655440000' \
  --header 'Content-Type: application/json' \
  --header 'Cookie: your-session-token' \
  --data '{
    "email": "[email protected]",
    "phone": "+34645678901",
    "city": "Valencia",
    "postal_code": "46001"
  }'

Example Response

{
  "user_id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "[email protected]",
  "name": "Maria",
  "surname": "Garcia",
  "phone": "+34634567890",
  "address": "Calle Nueva 456",
  "city": "Madrid",
  "country": "Spain",
  "postal_code": "28013",
  "gender": "female",
  "birth_date": "1990-05-15",
  "role": "USER",
  "status": "ON",
  "avatar": "",
  "document_type": "DNI",
  "document_number": "12345678A",
  "created_at": "2024-01-15T10:30:00.000Z",
  "updated_at": "2024-03-05T15:45:00.000Z"
}

Error Responses

400 Bad Request - Missing ID

{
  "statusCode": 400,
  "statusMessage": "ID requerido"
}

400 Bad Request - Validation Error

Returned when the request body fails validation.
{
  "statusCode": 400,
  "statusMessage": "Email inválido"
}
Common validation errors:
  • Email inválido - Invalid email format
  • El nombre es obligatorio - Name must be at least 2 characters
  • El apellido es obligatorio - Surname must be at least 2 characters
  • El teléfono es obligatorio - Phone must be at least 6 characters

404 Not Found - Client Not Found

Returned when no client exists with the specified ID or when the user is not a client (role is not USER). This is indicated by Prisma error code P2025.
{
  "statusCode": 404,
  "statusMessage": "Cliente no encontrado"
}

409 Conflict - Duplicate Email

Returned when attempting to update to an email address that is already used by another client.
{
  "statusCode": 409,
  "statusMessage": "El correo electrónico ya está en uso por otro cliente"
}

Implementation Details

  • All fields in the request body are optional
  • Only the provided fields will be updated; others remain unchanged
  • Email uniqueness is checked against other users (excluding the current client)
  • The update query verifies that role: 'USER' to ensure only clients can be updated via this endpoint
  • The password field is always excluded from responses
  • If birth_date is provided, it’s converted to a Date object before storage
  • The updated_at timestamp is automatically updated by Prisma
  • Input validation is performed using Zod schemas
  • The endpoint uses Prisma’s update method with a where clause that includes both user_id and role

Partial Updates

This endpoint supports partial updates. You can update a single field:
{
  "status": "OFF"
}
Or multiple fields at once:
{
  "phone": "+34612345678",
  "address": "New Street 123",
  "city": "Barcelona",
  "postal_code": "08001"
}

Status Management

The status field can be used to activate or deactivate client accounts:
  • ON: Active client account
  • OFF: Inactive client account (soft delete alternative)
Setting status to OFF is recommended over deletion for maintaining historical records.

Source Reference

Implemented in server/api/clients/[id].put.ts

Build docs developers (and LLMs) love