Skip to main content

POST /api/booking

Creates a new virtual class booking for an authenticated user. The booking is initially created with a pending status and is later updated to scheduled when the Google Calendar event is confirmed via webhook.

Authentication

This endpoint requires authentication. The user must be logged in with a valid session.

Request Body

start
string
required
ISO 8601 datetime string for the class start timeExample: "2026-03-15T10:00:00Z"
end
string
required
ISO 8601 datetime string for the class end timeExample: "2026-03-15T11:00:00Z"
isGroupClass
boolean
required
Whether this is a group class or individual class
  • true: Group class (grupal)
  • false: Individual class (individual)
studentsCount
number
required
Maximum number of students for the classFor individual classes, this is typically 1. For group classes, specify the maximum capacity.
text
string
Learning focus or objectives for the classExample: "Focus on conversational English and pronunciation"
price
number
required
Price for the class in cents or smallest currency unitExample: 5000 (represents $50.00)
preferenceId
string
required
Mercado Pago payment preference IDThis ID links the booking to a payment record and must be unique.

Response

success
boolean
Indicates whether the booking was created successfully
status
number
HTTP status code
  • 200: Booking created successfully
  • 400: Missing or invalid request data
  • 401: User not authenticated
  • 500: Server error during booking creation

Example Request

curl -X POST https://your-domain.com/api/booking \
  -H "Content-Type: application/json" \
  -H "Cookie: authjs.session-token=YOUR_SESSION_TOKEN" \
  -d '{
    "start": "2026-03-15T10:00:00Z",
    "end": "2026-03-15T11:00:00Z",
    "isGroupClass": false,
    "studentsCount": 1,
    "text": "Focus on business English vocabulary",
    "price": 5000,
    "preferenceId": "mp-pref-123456789"
  }'

Example Response

{
  "success": true,
  "status": 200
}

Error Responses

Database Record

When a booking is created, a new VirtualClass record is inserted with the following fields:
  • bookedById: Authenticated user’s ID
  • startTime: Converted to Date object from start
  • endTime: Converted to Date object from end
  • classType: “grupal” or “individual” based on isGroupClass
  • classPrice: Numeric price value
  • maxParticipants: From studentsCount
  • preferenceId: Payment preference ID
  • learningFocus: From text parameter
  • participantsIds: Array initialized with the creator’s user ID
  • status: Initially set to pending

Notes

  • The booking is created with a pending status initially
  • After successful payment confirmation and Google Calendar event creation, the booking status is updated to scheduled via a webhook
  • The user who creates the booking is automatically added as the first participant
  • The preferenceId must match a valid Mercado Pago payment preference

Build docs developers (and LLMs) love