POST
/
wp-json
/
latepoint-api
/
v1
/
bookings
{
  "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"
    }
  }
}

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

X-API-Key
string
required
Your LatePoint API key. You can get it from the admin panel.

Request Body

Required Fields

service_id
integer
required
ID of the service to book
agent_id
integer|string
required
ID of the agent who will provide the service. Use “any” or “-1” for automatic agent assignment based on availability
start_date
string
required
Booking date (format: YYYY-MM-DD)
start_time
string
required
Start time (format: HH:MM in 24-hour format)

Customer Information

customer_id
integer
ID of an existing customer. If provided, new customer fields are ignored
customer.first_name
string
Customer first name (required if customer_id is not provided)
customer.last_name
string
Customer last name (required if customer_id is not provided)
customer.email
string
Customer email (required if customer_id is not provided)
customer.phone
string
Customer phone

Optional Fields

location_id
integer
Location ID (uses default location if not specified)
duration
integer
Custom duration in minutes (uses service default duration)
price
string
Custom price (uses service default price)
status
string
default:"pending"
Initial booking statusPossible values:
  • pending - Pending
  • approved - Approved
  • cancelled - Cancelled
notes
string
Additional notes for the booking
send_confirmation
boolean
default:"true"
Whether to send confirmation email to customer

Respuesta

Success Response (201 Created)

status
string
Response status (“success”)
data
object
Created booking object

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": "ana.lopez@email.com",
      "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": "juan.perez@email.com",
      "phone": "+52 555 123 4567"
    },
    "agent": {
      "id": 3,
      "display_name": "Dr. María García",
      "email": "maria.garcia@clinica.com"
    },
    "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

{
  "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:
  1. Agent Availability: Verifies that the agent is available at the requested time
  2. Working Hours: Validates that the time is within the agent’s working hours
  3. Service Duration: Verifies there is enough time to complete the service
  4. Valid Dates: Does not allow bookings on past dates
  5. 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.

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: 'ana.lopez@email.com',
    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'
};```