Skip to content

Get Booking Slots

About

The bookingSlots query retrieves available time slots for a booking product on a specific date. This query is essential for building the booking UI — when a customer selects a date, you use this query to fetch and display the available slots they can choose from before adding the product to cart.

Why This Query Is Needed

When adding a booking product to the cart, the booking input requires a specific time slot (e.g., "slot": "12:00 PM - 01:00 PM"). But the available slots depend on the product's configuration (duration, break time, operating hours) and the selected date (day-of-week availability, existing bookings). This query resolves all of that and returns only the slots that are actually available for selection.

The typical flow is:

  1. Query the product to get bookingProductId from the bookingProducts relationship
  2. Customer selects a date on the frontend
  3. Query bookingSlots with the bookingProductId and selected date to get available slots
  4. Customer picks a slot from the results
  5. Add to cart using the selected slot value in the booking JSON

Different Response Structures

The response structure differs based on the booking type:

  • Default, Appointment, Table, Event — Slots are returned as a flat list. Each item has from, to, timestamp, and qty fields directly on it.
  • Rental (Hourly) — Slots are returned in a grouped structure. Each item has a time field (the time range group label) and a slots array containing the individual hourly slots within that group.
  • Rental (Daily) and Event — These types typically don't use time slots (daily rentals use date ranges, events use ticket quantities), so this query may return an empty array for them.

Arguments

ArgumentTypeRequiredDescription
idInt!YesThe bookingProductId — obtained from the product query's bookingProducts relationship (not the product ID).
dateString!YesThe date to check for available slots in YYYY-MM-DD format.

Response Fields

Non-Rental Booking Types (Flat Structure)

FieldTypeDescription
slotIdIntSlot identifier (may be null).
fromStringSlot start time (e.g., "10:00 AM").
toStringSlot end time (e.g., "11:00 AM").
timestampStringUnix timestamp range in format "from-to" (e.g., "1774413000-1774416600").
qtyStringNumber of available bookings for this slot.

Rental Hourly Booking Type (Grouped Structure)

FieldTypeDescription
slotIdIntSlot identifier (may be null).
timeStringTime range group label (e.g., "10:00 AM - 12:00 PM").
slots[Slot]Array of individual hourly slots within the time range group.
slots[].fromStringIndividual slot start time (e.g., "10:00 AM").
slots[].toStringIndividual slot end time (e.g., "11:00 AM").
slots[].timestampStringUnix timestamp range for the individual slot.
slots[].qtyStringNumber of available bookings for this individual slot.

Response by Booking Type

Booking TypeResponse StructureFields to Query
DefaultFlat listslotId, from, to, timestamp, qty
AppointmentFlat listslotId, from, to, timestamp, qty
TableFlat listslotId, from, to, timestamp, qty
EventEmpty array (events use ticket quantities, not time slots)
Rental (Hourly)Grouped by time rangesslotId, time, slots
Rental (Daily)Empty array (daily rentals use date ranges, not time slots)

How to Get the bookingProductId

The id parameter for this query is not the product ID — it is the bookingProductId from the product's bookingProducts relationship. Query it like this:

graphql
query getProduct($id: ID!) {
  product(id: $id) {
    id
    name
    bookingProducts {
      edges {
        node {
          _id           # This is the bookingProductId to use
          type          # default, appointment, rental, table, event
        }
      }
    }
  }
}

Use the _id value from bookingProducts.edges.node as the id argument in the bookingSlots query.

Common Use Cases

Build a Date + Slot Picker (Non-Rental)

graphql
# Step 1: User selects a date, fetch available slots
query {
  bookingSlots(id: 1, date: "2026-03-26") {
    from
    to
    timestamp
    qty
  }
}

Then use the from and to values to construct the slot field for the add-to-cart mutation:

json
{
  "booking": "{\"type\":\"appointment\",\"date\":\"2026-03-26\",\"slot\":\"10:00 AM - 11:00 AM\"}"
}

Build an Hourly Rental Slot Picker

graphql
# Fetch grouped rental slots
query {
  bookingSlots(id: 5, date: "2026-03-26") {
    time
    slots
  }
}

Display the time groups as headers and individual slots as selectable options. Then use the selected slot for add-to-cart:

json
{
  "booking": "{\"type\":\"rental\",\"renting_type\":\"hourly\",\"date\":\"2026-03-26\",\"slot\":\"10:00 AM - 11:00 AM\"}"
}

Best Practices

  1. Use bookingProductId, Not Product ID — The id argument must be the _id from the bookingProducts relationship, not the main product ID
  2. Check for Empty Results — An empty array means no slots are available for that date; prompt the user to select a different date
  3. Check qty — Only display slots where qty is greater than 0
  4. Handle Both Structures — Use the product's booking type to determine whether to expect flat slots or grouped rental slots
  5. Refresh on Date Change — Re-query whenever the user changes the selected date
  • Single Product - Get product details including bookingProducts relationship
  • Add to Cart - Add booking product to cart with selected slot

Released under the MIT License.