Setting the file. One moment. Wix Restaurants Reservations · Wix Vibe Headless · wix/skills · Skills DocsWix Blog
references/restaurants/app/rest/wix-restaurants-reservations.js
JavaScript·107 lines·6 KB
* Full model: https://dev.wix.com/docs/api-reference/business-solutions/restaurants/reservations/reservation-locations/reservation-location-object.md
15 *
16 * TimeSlot (from getTimeSlots):
17 * { startDate, duration, status, manualApproval }
18 * status: "AVAILABLE" | "UNAVAILABLE" | "NON_WORKING_HOURS" — offer only AVAILABLE slots.
19 *
20 * Reservation (from createHeldReservation / reserveReservation):
21 * { id, revision, status, details: { reservationLocationId, startDate, endDate, partySize }, reservee, paymentStatus }
22 * status: "HELD" → "RESERVED" (auto-approved) or "REQUESTED" (manual approval required) after reserve.
23 * Full model: https://dev.wix.com/docs/api-reference/business-solutions/restaurants/reservations/reservations/reservation-object.md
24 */
25
26/**
27 * List the site's reservation locations (up to 100).
28 * GET https://www.wixapis.com/table-reservations/reservation-locations/v1/reservation-locations
29 * @returns {Promise<object[]>}
30 */
31export async function listReservationLocations() {
32 const res = await wixApiRequest(
33 "/table-reservations/reservation-locations/v1/reservation-locations",
34 { method: "GET" },
35 );
36 return res?.reservationLocations ?? [];
37}
38
39/**
40 * Get reservation time slots for a location on a date, filtered to AVAILABLE only.
41 * Use slotsBefore / slotsAfter to fan out around the chosen date.
42 * POST https://www.wixapis.com/table-reservations/reservations/v1/time-slots
43 * https://dev.wix.com/docs/api-reference/business-solutions/restaurants/reservations/time-slots/get-time-slots.md
44 * @param {string} reservationLocationId
45 * @param {string} date ISO-8601 datetime e.g. "2026-07-01T19:00:00.000Z"
46 * @param {number} partySize
47 * @param {{ slotsBefore?: number, slotsAfter?: number, duration?: number }} [options]
48 * @returns {Promise<{ timeSlots: object[], availableTimeSlots: object[] }>}
49 */
50export async function getTimeSlots(reservationLocationId, date, partySize, { slotsBefore = 4, slotsAfter = 4, duration } = {}) {
51 if (!reservationLocationId || !date || !partySize) {
52 throw new Error("getTimeSlots: reservationLocationId, date and partySize are required.");
53 }
54 const res = await wixApiRequest("/table-reservations/reservations/v1/time-slots", {
55 method: "POST",
56 body: { reservationLocationId, date, partySize, slotsBefore, slotsAfter, ...(duration ? { duration } : {}) },
57 });
58 const timeSlots = res?.timeSlots ?? [];
59 return { timeSlots, availableTimeSlots: timeSlots.filter((s) => s.status === "AVAILABLE") };
60}
61
62/**
63 * Hold a reservation for 10 minutes while the visitor fills in their details.
64 * Returns a reservation with status "HELD" — keep its id and revision for reserveReservation.
65 * POST https://www.wixapis.com/table-reservations/reservations/v1/reservations/hold
66 * @param {string} reservationLocationId
67 * @param {string} startDate ISO-8601 datetime of the chosen time slot.
68 * @param {number} partySize
69 * @returns {Promise<object>} The held reservation ({ id, revision, status: "HELD", ... }).
70 */
71export async function createHeldReservation(reservationLocationId, startDate, partySize) {
72 if (!reservationLocationId || !startDate || !partySize) {
73 throw new Error("createHeldReservation: reservationLocationId, startDate and partySize are required.");
74 }
75 const res = await wixApiRequest("/table-reservations/reservations/v1/reservations/hold", {
76 method: "POST",
77 body: { reservationDetails: { reservationLocationId, startDate, partySize } },
78 });
79 const reservation = res?.reservation;
80 if (!reservation?.id) throw new Error("Failed to hold the reservation (the slot may no longer be available).");
81 return reservation;
82}
83
84/**
85 * Confirm a held reservation with the visitor's details. Moves status from "HELD" to
86 * "RESERVED" (auto-approval) or "REQUESTED" (manual approval required).
87 * reservee.firstName and reservee.phone (E.164, e.g. "+15551234567") are REQUIRED.
88 * Pass the revision returned by createHeldReservation. Holds expire after 10 minutes.
89 * POST https://www.wixapis.com/table-reservations/reservations/v1/reservations/{id}/reserve
90 * @param {string} reservationId
91 * @param {string} revision
92 * @param {{ firstName: string, phone: string, lastName?: string, email?: string, marketingConsent?: boolean }} reservee
93 * @returns {Promise<object>} The updated reservation.
94 */
95export async function reserveReservation(reservationId, revision, reservee) {
96 if (!reservationId || !revision) throw new Error("reserveReservation: reservationId and revision are required.");
97 if (!reservee?.firstName || !reservee?.phone) {
98 throw new Error("reserveReservation: reservee.firstName and reservee.phone are required.");
99 }
100 const res = await wixApiRequest(
101 `/table-reservations/reservations/v1/reservations/${encodeURIComponent(reservationId)}/reserve`,
102 { method: "POST", body: { revision, reservee } },
103 );
104 const reservation = res?.reservation;
105 if (!reservation?.id) throw new Error("Failed to confirm the reservation (the hold may have expired — start over).");
106 return reservation;
107}