Description
This endpoint allows you to create a new booking in your LatePoint system. It includes automatic availability validation, creation of new customers if necessary, and application of configured business rules.
Authentication
Your LatePoint API key. You can get it from the admin panel.
Request Body
Required Fields
ID of the service to book
ID of the agent who will provide the service. Use “any” or “-1” for automatic agent assignment based on availability
Booking date (format: YYYY-MM-DD)
Start time (format: HH:MM in 24-hour format)
ID of an existing customer. If provided, new customer fields are ignored
Customer first name (required if customer_id is not provided)
Customer last name (required if customer_id is not provided)
Customer email (required if customer_id is not provided)
Optional Fields
Location ID (uses default location if not specified)
Custom duration in minutes (uses service default duration)
Custom price (uses service default price)
Initial booking status Possible values:
pending - Pending
approved - Approved
cancelled - Cancelled
Additional notes for the booking
Whether to send confirmation email to customer
Respuesta
Success Response (201 Created)
Response status (“success”)
Created booking object Show Created Booking Structure
Unique ID of the created booking
Unique code generated for the booking
Calculated end time (HH:MM)
Customer information (created or existing)
Creation date and time (ISO 8601)
Examples
Create Booking with Existing Customer
curl -X POST "http://latepoint-dev.local/wp-json/latepoint-api/v1/bookings" \
-H "X-API-Key: lp_n1k6BVf3h7JRyjXkWMSoXi0BBZYRaOLL4QohDPQJ" \
-H "Content-Type: application/json" \
-d '{
"service_id": 2,
"agent_id": 1,
"customer_id": 2,
"start_date": "2025-09-01",
"start_time": "14:30",
"status": "approved",
"notes": "Consulta de seguimiento"
}'
Create Booking with New Customer
curl -X POST "http://latepoint-dev.local/wp-json/latepoint-api/v1/bookings" \
-H "X-API-Key: lp_n1k6BVf3h7JRyjXkWMSoXi0BBZYRaOLL4QohDPQJ" \
-H "Content-Type: application/json" \
-d '{
"service_id": 2,
"agent_id": 1,
"start_date": "2025-09-01",
"start_time": "16:00",
"customer": {
"first_name": "Ana",
"last_name": "López",
"email": "[email protected] ",
"phone": "+52 555 987 6543"
},
"status": "pending",
"send_confirmation": true
}'
Example Response
Successfully Created Booking
{
"status" : "success" ,
"data" : {
"id" : 156 ,
"booking_code" : "LP-2024-002" ,
"status" : "approved" ,
"start_date" : "2024-01-20" ,
"start_time" : "14:30" ,
"end_time" : "15:30" ,
"duration" : 60 ,
"price" : "75.00" ,
"customer" : {
"id" : 45 ,
"first_name" : "Juan" ,
"last_name" : "Pérez" ,
"email" : "[email protected] " ,
"phone" : "+52 555 123 4567"
},
"agent" : {
"id" : 3 ,
"display_name" : "Dr. María García" ,
"email" : "[email protected] "
},
"service" : {
"id" : 7 ,
"name" : "Consulta General" ,
"duration" : 60 ,
"price" : "75.00"
},
"location" : {
"id" : 1 ,
"name" : "Clínica Principal" ,
"address" : "Av. Reforma 123, CDMX"
},
"notes" : "Consulta de seguimiento" ,
"created_at" : "2024-01-15T10:30:00Z"
}
}
Error Codes
Error 400 - Invalid Data
Error 409 - Time Conflict
Error 422 - Validation Failed
Error 403 - Insufficient Permissions
{
"status" : "error" ,
"error" : {
"code" : "invalid_request" ,
"message" : "Invalid input data" ,
"details" : {
"service_id" : "The specified service does not exist" ,
"start_time" : "Invalid time format, use HH:MM" ,
"customer.email" : "Invalid email"
}
}
}
Validations
Automatic Validations
The system performs the following validations automatically:
Agent Availability : Verifies that the agent is available at the requested time
Working Hours : Validates that the time is within the agent’s working hours
Service Duration : Verifies there is enough time to complete the service
Valid Dates : Does not allow bookings on past dates
Unique Email : If creating a new customer, verifies the email is not already in use
Business Rules
Existing vs New Customer : If you provide customer_id, all customer fields are ignored. If you don’t provide customer_id, the first_name, last_name and email fields are required.
Availability Check : Always verify availability using the /availability endpoint before creating a booking to avoid conflicts.
Booking Codes : Booking codes are automatically generated following the pattern LP-YYYY-NNN where YYYY is the year and NNN is a sequential number.
Recommended Flow
1. Check Availability
// First check availability
const availabilityResponse = await fetch (
`/wp-json/latepoint-api/v1/availability?service_id=7&agent_id=3&date=2024-01-20&duration=60`
);
const availability = await availabilityResponse . json ();
if ( availability . data . available_slots . includes ( '14:30' )) {
// Proceed with booking creation
}
2. Create the Booking
// Create the booking if available
const bookingResponse = await fetch ( '/wp-json/latepoint-api/v1/bookings' , {
method: 'POST' ,
headers: {
'X-API-Key' : 'tu_api_key' ,
'Content-Type' : 'application/json'
},
body: JSON . stringify ( bookingData )
});
3. Handle the Response
if ( bookingResponse . ok ) {
const result = await bookingResponse . json ();
console . log ( 'Booking created:' , result . data . booking_code );
} else {
const error = await bookingResponse . json ();
console . error ( 'Error:' , error . error . message );
}
Common Use Cases
1. Quick Booking (Existing Customer)
// For customers already in the system
const quickBooking = {
service_id: 7 ,
agent_id: 3 ,
customer_id: 45 ,
start_date: '2024-01-20' ,
start_time: '14:30' ,
status: 'approved'
};
2. First Booking (New Customer)
// For new customers
const newCustomerBooking = {
service_id: 7 ,
agent_id: 3 ,
start_date: '2024-01-20' ,
start_time: '14:30' ,
customer: {
first_name: 'Ana' ,
last_name: 'López' ,
email: '[email protected] ' ,
phone: '+52 555 987 6543'
},
send_confirmation: true
};
3. Booking with Custom Configuration
// With custom duration and price
const customBooking = {
service_id: 7 ,
agent_id: 3 ,
customer_id: 45 ,
start_date: '2024-01-20' ,
start_time: '14:30' ,
duration: 90 , // 90 minutes instead of default 60
price: '100.00' , // Custom price
notes: 'Extended session with complete evaluation'
}; ```