Skip to main content
POST
/
api
/
users
/
{userId}
/
reservations
Create Reservation
curl --request POST \
  --url https://api.example.com/api/users/{userId}/reservations \
  --header 'Content-Type: application/json' \
  --data '
{
  "doctorId": 123,
  "patientId": 123,
  "timeBlockId": 123,
  "reason": "<string>",
  "notes": "<string>"
}
'
{
  "id": 123,
  "date": "<string>",
  "timeBlockId": 123,
  "patientId": 123,
  "doctorId": 123,
  "status": "<string>",
  "reason": "<string>",
  "notes": "<string>",
  "createdAt": "<string>",
  "updatedAt": "<string>"
}

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header:
Authorization: Bearer <token>

Path Parameters

userId
integer
required
The ID of the user creating the reservation. This must match the authenticated user’s ID.

Request Body

doctorId
integer
required
The ID of the doctor for the appointment. Must be a positive integer and the doctor must exist in the system.
patientId
integer
required
The ID of the patient booking the appointment. Must be a positive integer and the patient must exist in the system.
timeBlockId
integer
required
The ID of the time block to reserve. Must be a positive integer, the time block must exist, and it cannot already be booked by another appointment.
reason
string
The reason for the appointment. Maximum 255 characters. Optional field that can be empty or null.
notes
string
Additional notes for the appointment. Maximum 1000 characters. Optional field that can be empty or null.

Validation Rules

  • doctorId: Required, must be a positive integer
  • patientId: Required, must be a positive integer
  • timeBlockId: Required, must be a positive integer
  • reason: Optional, maximum 255 characters
  • notes: Optional, maximum 1000 characters

Business Logic

The system performs the following validations before creating the reservation:
  1. Patient Exists: Verifies the patient ID corresponds to an existing user
  2. Doctor Exists: Verifies the doctor ID corresponds to an existing user
  3. Time Block Exists: Verifies the time block ID corresponds to an existing time block
  4. No Conflicts: Ensures the time block is not already reserved by another appointment
The appointment date is automatically set to the start time of the selected time block, and the status is set to PENDING by default.

Response

id
integer
The unique identifier for the created appointment
date
string
The appointment date and time (ISO 8601 format), automatically set from the time block’s startTime
timeBlockId
integer
The ID of the associated time block
patientId
integer
The ID of the patient
doctorId
integer
The ID of the doctor
status
string
The appointment status. Defaults to PENDING. Possible values: PENDING, CONFIRMED, CANCELLED, COMPLETED
reason
string
The reason for the appointment
notes
string
Additional notes for the appointment
createdAt
string
Timestamp when the appointment was created (ISO 8601 format)
updatedAt
string
Timestamp when the appointment was last updated (ISO 8601 format)

Error Responses

400 Bad Request

Returned when validation fails or business rules are violated:
{
  "error": "El paciente no existe"
}
{
  "error": "El doctor no existe"
}
{
  "error": "El bloque de tiempo no existe"
}
{
  "error": "Ya existe una reserva para este bloque de tiempo"
}

401 Unauthorized

Returned when the JWT token is missing or invalid:
{
  "error": "Unauthorized"
}

Example Request

curl -X POST https://api.example.com/api/users/42/reservations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "doctorId": 5,
    "patientId": 12,
    "timeBlockId": 42,
    "reason": "Consulta general",
    "notes": "Paciente presenta síntomas de gripe"
  }'

Example Response

{
  "id": 89,
  "date": "2026-03-15T10:00:00.000Z",
  "timeBlockId": 42,
  "patientId": 12,
  "doctorId": 5,
  "status": "PENDING",
  "reason": "Consulta general",
  "notes": "Paciente presenta síntomas de gripe",
  "createdAt": "2026-03-03T14:30:00.000Z",
  "updatedAt": "2026-03-03T14:30:00.000Z"
}

Build docs developers (and LLMs) love