> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: cancelReservation(reservationId: string, revision: string, options: CancelReservationOptions) # Method package: wixTableReservationsV2 # Method menu location: wixTableReservationsV2 --> reservations --> cancelReservation # Method Link: https://dev.wix.com/docs/velo/apis/wix-table-reservations-v2/reservations/cancel-reservation.md # Method Description: Cancels a reservation. Sets the reservation status to `CANCELED`. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Cancel a `WALK_IN` reservation that has no phone number (page code) ```javascript import { reservations } from 'wix-table-reservations.v2'; /* Sample reservationId value: "36b144c4-9cb5-4c92-96c1-5027301cac05" * Sample revision value: 1 */ reservations.cancelReservation(reservationId, revision) .then((canceledReservation) => { const updatedRevision = canceledReservation.revision; const status = canceledReservation.status; console.log('Success! Canceled the reservation:', canceledReservation); return canceledReservation; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * { * "reservation": { * "status": "CANCELED", * "source": "UNKNOWN", * "details": { * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2", * "tableIds": [], * "startDate": "2024-12-06T14:30:00.000Z", * "endDate": "2024-12-06T16:00:00.000Z", * "partySize": 2 * }, * "revision": "2", * "migrationNotes": [], * "tablesWithReservationConflicts": [], * "_id": "36b144c4-9cb5-4c92-96c1-5027301cac05", * "_createdDate": "2024-01-22T11:20:02.781Z" * } * } */ ``` ## Cancel an `ONLINE` reservation with a phone number (backend) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { reservations } from 'wix-table-reservations.v2'; /* Sample reservationId value: "26cdab39-9fb5-45b8-867e-5f6d85541468" * Sample revision value: 1 * Sample phone value: "+972555555555" */ export const myCancelReservationFunction = webMethod(Permissions.Anyone, async (reservationId, revision, phone) => { try { const canceledReservation = await reservations.cancelReservation(reservationId, revision, phone); const updatedRevision = canceledReservation.revision; const status = canceledReservation.status; console.log('Success! Canceled the reservation:', canceledReservation); return canceledReservation; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "reservation": { * "status": "CANCELED", * "source": "UNKNOWN", * "details": { * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2", * "tableIds": [], * "startDate": "2024-12-06T14:30:00.000Z", * "endDate": "2024-12-06T16:00:00.000Z", * "partySize": 2 * }, * "revision": "2", * "migrationNotes": [], * "tablesWithReservationConflicts": [], * "_id": "26cdab39-9fb5-45b8-867e-5f6d85541468", * "_createdDate": "2024-01-22T11:24:56.658Z" * } * } */ ``` ## Close a restaurant and cancel all reservations on a given day ```javascript /* This example requires the following elements: * A dropdown element named `locationDropdown`. * A date picker element named 'datePicker`. * A button named `confirmButton`. * A text element named `cancellationNotice`. */ /********************************************** * Backend code - reservationLocations.web.js * **********************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { reservationLocations } from 'wix-table-reservations.v2'; import { locations } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; export const getRestaurantLocation = webMethod(Permissions.Anyone, async (location_id) => { const elevatedGetLocation = elevate(locations.getLocation); try { const result = await elevatedGetLocation(location_id); return result; } catch (error) { console.error(error); // Handle the error } }); export const getRestautantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, options) => { const elevatedGetReservationLocations = elevate(reservationLocations.getReservationLocation); try { const result = await elevatedGetReservationLocations(reservationLocationId, options); return result; } catch (error) { console.error(error); // Handle the error } }); export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => { const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation); try { const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject); return result; } catch (error) { console.error(error); // Handle the error } }); /************************************** * Backend code - reservations.web.js * *************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { reservations } from 'wix-table-reservations.v2'; import { elevate } from 'wix-auth'; export const queryReservationsInDateRange = webMethod(Permissions.Anyone, async (startDate, endDate) => { const elevatedQueryReservations = elevate(reservations.queryReservations); try { const result = await elevatedQueryReservations() .ge('details.startDate', startDate) .lt('details.startDate', endDate) .find(); return result; } catch (error) { console.error(error); // Handle the error } }); /************* * Page code * *************/ import { reservationLocations } from 'wix-table-reservations.v2'; import { reservations } from 'wix-table-reservations.v2'; import { getRestaurantLocation } from 'backend/reservationLocations.web'; import { getRestautantDetails } from 'backend/reservationLocations.web'; import { updateRestaurantDetails } from 'backend/reservationLocations.web'; import { queryReservationsInDateRange } from 'backend/reservations.web'; $w.onReady(async function () { $w('#datePicker').hide(); $w('#confirmButton').hide(); $w('#cancellationNotice').hide(); // Set the earliest selectable date to the day after the current date var tomorrowsDate = new Date(); tomorrowsDate.setDate(tomorrowsDate.getDate() + 1); $w('#datePicker').minDate = tomorrowsDate; $w('#datePicker').value = tomorrowsDate; //Get the list of reservation locations const myReservationLocationList = await (async () => { try { let fullListObject = await reservationLocations.listReservationLocations(); return fullListObject.reservationLocations; } catch (error) { console.error(error); // Handle the error } })(); //Create an array to hold names and values for our dropdown list let dropdownOptions = []; for (const object in myReservationLocationList) { //Use the _id stored in the reservation location's location object to get the location's name from the `locations` service const locationObject = await getRestaurantLocation(myReservationLocationList[object].location._id); dropdownOptions.push({ "label": locationObject.name, "value": myReservationLocationList[object]._id }) } //Populate our dropdown list with the array $w("#locationDropdown").options = dropdownOptions; $w('#locationDropdown').onChange((event) => { if ($w('#locationDropdown').value) { $w('#datePicker').show(); $w('#confirmButton').show(); } }); $w('#confirmButton').onClick(async (event) => { const options = { "fieldsets": "FULL" } const selectedLocation = await getRestautantDetails($w('#locationDropdown').value, options) //Create a new special hour period to push to the list in our reservation location's business schedule const selectedDate = $w('#datePicker').value; const dayAfterSelectedDate = new Date(selectedDate); dayAfterSelectedDate.setDate(selectedDate.getDate() + 1); const mySpecialHourPeriod = { "startDate": selectedDate, "endDate": dayAfterSelectedDate, "isClosed": true } if (!("businessSchedule" in selectedLocation.configuration.onlineReservations)) { //Handle business schedule configuration } selectedLocation.configuration.onlineReservations.businessSchedule.specialHourPeriod.push(mySpecialHourPeriod); await updateRestaurantDetails(selectedLocation._id, selectedLocation); //Create a variable to hold of names and phone numbers of canceled reservations. let canceledReservationsNote = "Notify of cancellation:\n"; //Query for reservations on the selected date and cancel any at our selected reservation location let reservationsOnSelectedDate = await queryReservationsInDateRange(selectedDate, dayAfterSelectedDate); for (let reservation in reservationsOnSelectedDate._items) { if (reservationsOnSelectedDate._items[reservation].details.reservationLocationId == selectedLocation._id) { let options = { "phone": reservationsOnSelectedDate._items[reservation].reservee.phone } const canceledReservation = await (async () => { try { return reservations.cancelReservation(reservationsOnSelectedDate._items[reservation]._id, reservationsOnSelectedDate._items[reservation].revision, options) } catch (error) { console.error(error); // Handle the error return false; } })(); if (canceledReservation) { canceledReservationsNote += "First name: " + reservationsOnSelectedDate._items[reservation].reservee.firstName + ". Last name: " + reservationsOnSelectedDate._items[reservation].reservee.lastName + ". Phone: " + reservationsOnSelectedDate._items[reservation].reservee.phone + "\n"; } } } $w('#cancellationNotice').text = canceledReservationsNote; $w('#cancellationNotice').show(); }); }); ``` ---