Skip to content

Bookings API

API for managing all bookings

GET /bookings

Get all bookings

Query Parameters

ParameterTypeDescriptionDefault
pagenumberCurrent page1
limitnumberItems per page20
statusstringFilter by status-
fromstringStart date (ISO 8601)-
tostringEnd date (ISO 8601)-
customerIdstringFilter by customer-
serviceIdstringFilter by service-
staffIdstringFilter by staff-

Status Values

StatusDescription
pendingPending confirmation
confirmedConfirmed
completedCompleted
cancelledCancelled
no_showNo show

Response

json
{
  "success": true,
  "data": [
    {
      "id": "bk_123456",
      "customer": {
        "id": "cust_123",
        "name": "John Doe",
        "email": "john@email.com",
        "phone": "081-234-5678"
      },
      "service": {
        "id": "svc_456",
        "name": "Haircut",
        "duration": 60,
        "price": 300
      },
      "staff": {
        "id": "staff_789",
        "name": "Daeng"
      },
      "dateTime": "2024-01-15T10:00:00Z",
      "endTime": "2024-01-15T11:00:00Z",
      "status": "confirmed",
      "notes": "Special appointment request",
      "createdAt": "2024-01-10T08:30:00Z",
      "updatedAt": "2024-01-10T08:30:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 150,
    "totalPages": 8
  }
}

GET /bookings/:id

Get booking details by ID

Path Parameters

ParameterTypeDescription
idstringBooking ID (e.g., bk_123456)

Response

json
{
  "success": true,
  "data": {
    "id": "bk_123456",
    "customer": {
      "id": "cust_123",
      "name": "John Doe",
      "email": "john@email.com",
      "phone": "081-234-5678"
    },
    "service": {
      "id": "svc_456",
      "name": "Haircut",
      "duration": 60,
      "price": 300
    },
    "staff": {
      "id": "staff_789",
      "name": "Daeng"
    },
    "dateTime": "2024-01-15T10:00:00Z",
    "endTime": "2024-01-15T11:00:00Z",
    "status": "confirmed",
    "notes": "Special appointment request",
    "payment": {
      "status": "paid",
      "method": "card",
      "amount": 300,
      "paidAt": "2024-01-15T09:45:00Z"
    },
    "createdAt": "2024-01-10T08:30:00Z",
    "updatedAt": "2024-01-10T08:30:00Z"
  }
}

POST /bookings

Create a new booking

Request Body

json
{
  "customerId": "cust_123",
  "serviceId": "svc_456",
  "staffId": "staff_789",
  "dateTime": "2024-01-15T10:00:00Z",
  "notes": "Special appointment request",
  "source": "website"
}
FieldTypeRequiredDescription
customerIdstringCustomer ID
serviceIdstringService ID
staffIdstringStaff ID
dateTimestringDesired date and time (ISO 8601)
notesstringNotes
sourcestringSource (website, app, walk-in)

Response

json
{
  "success": true,
  "data": {
    "id": "bk_789012",
    "customer": { ... },
    "service": { ... },
    "staff": { ... },
    "dateTime": "2024-01-15T10:00:00Z",
    "status": "pending",
    "createdAt": "2024-01-15T09:00:00Z"
  },
  "message": "Booking created successfully"
}

PATCH /bookings/:id

Update booking status or details

Request Body

json
{
  "status": "confirmed",
  "dateTime": "2024-01-15T11:00:00Z",
  "notes": "Updated notes"
}
FieldTypeRequiredDescription
statusstringNew status
dateTimestringNew date and time
notesstringNotes

Response

json
{
  "success": true,
  "data": {
    "id": "bk_123456",
    "status": "confirmed",
    "updatedAt": "2024-01-15T09:30:00Z"
  },
  "message": "Booking updated successfully"
}

DELETE /bookings/:id

Cancel a booking

Query Parameters

ParameterTypeRequiredDescription
reasonstringReason for cancellation
notifyCustomerbooleanNotify the customer (default: true)

Response

json
{
  "success": true,
  "data": {
    "id": "bk_123456",
    "status": "cancelled",
    "cancelledAt": "2024-01-15T09:30:00Z"
  },
  "message": "Booking cancelled successfully"
}

Example Code

Create a New Booking

typescript
async function createBooking(bookingData: {
  customerId: string;
  serviceId: string;
  staffId: string;
  dateTime: string;
}) {
  const response = await fetch('https://api.booking-platform.com/v1/bookings', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(bookingData),
  });

  if (!response.ok) {
    const error = await response.json();
    throw new Error(error.error.message);
  }

  return response.json();
}

// Usage
const booking = await createBooking({
  customerId: 'cust_123',
  serviceId: 'svc_456',
  staffId: 'staff_789',
  dateTime: '2024-01-15T10:00:00Z',
});

Get Today's Bookings

typescript
async function getTodayBookings() {
  const today = new Date().toISOString().split('T')[0];
  
  const response = await fetch(
    `https://api.booking-platform.com/v1/bookings?from=${today}T00:00:00Z&to=${today}T23:59:59Z`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
      },
    }
  );

  const { data, pagination } = await response.json();
  return data;
}

Cancel a Booking

typescript
async function cancelBooking(bookingId: string, reason?: string) {
  const response = await fetch(
    `https://api.booking-platform.com/v1/bookings/${bookingId}?reason=${encodeURIComponent(reason || 'Customer cancelled')}`,
    {
      method: 'DELETE',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
      },
    }
  );

  return response.json();
}

Next Steps

Released under the MIT License.