createHeldReservation( )
Creates a new temporary reservation and holds it for the customer for 10 minutes.
Description
Creates a new reservation with the HELD
status. HELD
reservations are intended to reserve seats and tables for a party in a selected time slot while they enter further reservation details, such as names and contact information. Reservations with the HELD
status are only valid for 10 minutes. Trying to change a HELD
reservation’s status after 10 minutes returns an error.
You cannot call updateReservation()
to change a reservation’s status from HELD
. Trying to do so returns an error. Instead, you should use reserveReservation()
.
If you do not wish to have HELD
reservations in your flow, you can create a reservation with all required details using createReservation()
.
Syntax
function createHeldReservation(reservationDetails: HeldReservationDetails): Promise<CreateHeldReservationResponse>
createHeldReservation Parameters
NAME
TYPE
DESCRIPTION
Held reservation information to update.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
Reservation.
Was this helpful?
1import { reservations } from 'wix-table-reservations.v2';23/* Sample reservationDetails value:4 * {5 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",6 * "startDate": new Date("2024-12-14T15:30:00Z"),7 * "partySize": 28 * }9 */1011reservations.createHeldReservation(reservationDetails)12 .then((createdHeldReservation) => {13 const id = createdHeldReservation._id;14 const status = createdHeldReservation.status;1516 console.log('Success! Created a held reservation:', createdHeldReservation);17 return createdHeldReservation;18 })19 .catch((error) => {20 console.error(error);21 // Handle the error22 });2324/* Promise resolves to:25 * {26 * "reservation": {27 * "status": "HELD",28 * "source": "UNKNOWN",29 * "details": {30 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",31 * "tableIds": [],32 * "startDate": "2024-12-14T15:30:00.000Z",33 * "endDate": "2024-12-14T17:00:00.000Z",34 * "partySize": 235 * },36 * "revision": "1",37 * "migrationNotes": [],38 * "tablesWithReservationConflicts": [],39 * "_id": "26bf7609-8bf4-45ac-aef0-dbb3e54f69ad",40 * "_createdDate": "2024-01-17T10:07:56.966Z"41 * }42 * }43 */44
This scenario sets up an interface that allows a site owner to select a reservation location and a party size, then select a time slot to reserve. Once a time slot is selected, the site owner can click a confirm button to create a held reservation at that time.
1/* This example requires the following elements:2 * A dropdown element named `locationDropdown`.3 * A dropdown element named `partySizeDropdown`.4 * A dropdown element named `timeSlotDropdown`.5 * A button named `confirmButton`.6 * A text element named `heldReservationNotification`.7 */89/**********************************************10 * Backend code - reservationLocations.web.js *11 **********************************************/1213import { Permissions, webMethod } from 'wix-web-module';14import { locations } from 'wix-business-tools.v2';15import { elevate } from 'wix-auth';1617export const getRestaurantLocation = webMethod(Permissions.Anyone, async (location_id) => {18 const elevatedGetLocation = elevate(locations.getLocation);1920 try {21 const result = await elevatedGetLocation(location_id);22 return result;23 } catch (error) {24 console.error(error);25 // Handle the error26 }27});2829/*************30 * Page code *31 *************/3233import { reservationLocations } from 'wix-table-reservations.v2';34import { reservations } from 'wix-table-reservations.v2';35import { timeSlots } from 'wix-table-reservations.v2';3637import { getRestaurantLocation } from 'backend/reservationLocations.web';3839$w.onReady(async function () {40 $w('#timeSlotDropdown').hide();41 $w('#partySizeDropdown').hide();42 $w('#confirmButton').hide();43 $w('#heldReservationNotification').hide();4445 //Get the list of reservation locations46 const myReservationLocationList = await (async () => {47 try {48 let fullListObject = await reservationLocations.listReservationLocations();49 return fullListObject.reservationLocations;50 } catch (error) {51 console.error(error);52 // Handle the error53 }54 })();5556 //Create an array to hold names and values for our locations dropdown list57 let locationDropdownOptions = [];58 for (const object in myReservationLocationList){59 //Use the _id stored in the reservation location's location object to get the location's name from the `locations` service60 const locationObject = await getRestaurantLocation(myReservationLocationList[object].location._id);61 locationDropdownOptions.push({62 "label": locationObject.name,63 "value": myReservationLocationList[object]._id64 })65 }66 //Populate our dropdown list with the array67 $w("#locationDropdown").options = locationDropdownOptions;6869 //Create an array to hold numbers and values for our party size dropdown list70 let partySizeDropdownOptions = [];71 for (let i = 1; i<10; i++){72 partySizeDropdownOptions.push({73 "label": String(i),74 "value": String(i)75 })76 }77 //Populate our dropdown list with the array78 $w("#partySizeDropdown").options = partySizeDropdownOptions;7980 $w('#locationDropdown').onChange( (event) => {81 if ($w('#locationDropdown').value) {82 $w('#partySizeDropdown').show();83 $w('#timeSlotDropdown').hide()84 $w('#confirmButton').hide();85 }86 });8788 $w('#partySizeDropdown').onChange( async (event) => {89 if ($w('#locationDropdown').value) {90 $w('#timeSlotDropdown').show()91 $w('#confirmButton').hide();9293 const timeSlotDetails = {94 "reservationLocationId": $w('#locationDropdown').value,95 "date": new Date(),96 "partySize": parseInt($w('#partySizeDropdown').value)97 };9899 const timeSlotOptions = {100 "duration": 30,101 "slotsAfter": 8,102 "slotsBefore": 0103 };104105 //Get the list of time slots according to the details and options above106 const availableTimeSlots = await (async () => {107 try {108 let fullListObject = await timeSlots.getTimeSlots(timeSlotDetails.reservationLocationId, timeSlotDetails.date, timeSlotDetails.partySize, timeSlotOptions);109 return fullListObject.timeSlots;110 } catch (error) {111 console.error(error);112 // Handle the error113 }114 })();115116 //Create an array to hold numbers and values for our time slot dropdown list117 let timeSlotDropdownOptions = [];118 for (const timeSlot in availableTimeSlots){119 if(availableTimeSlots[timeSlot].status == "AVAILABLE"){120 timeSlotDropdownOptions.push({121 "label": String(availableTimeSlots[timeSlot].startDate),122 "value": String(availableTimeSlots[timeSlot].startDate)123 })124 }125 }126 //Populate our dropdown list with the array127 $w("#timeSlotDropdown").options = timeSlotDropdownOptions;128 }129 });130131 $w('#timeSlotDropdown').onChange( async (event) => {132 if ($w('#timeSlotDropdown').value) {133 $w('#confirmButton').show();134 }135 });136137 $w('#confirmButton').onClick( async (event) => {138 //Get the list of time slots according to the details and options above139140 const createdHeldReservation = await (async () => {141 try {142 const reservationDetails = {143 "reservationLocationId": $w('#locationDropdown').value,144 "startDate": new Date($w("#timeSlotDropdown").value),145 "partySize": parseInt($w('#partySizeDropdown').value)146 };147148 return await reservations.createHeldReservation(reservationDetails);149 } catch (error) {150 console.error(error);151 // Handle the error152 }153 })();154155 if(createdHeldReservation){156 $w('#heldReservationNotification').text = "Held reservation created successfully."157 $w('#heldReservationNotification').show();158 }159 });160});161
1import { Permissions, webMethod } from 'wix-web-module';2import { reservations } from 'wix-table-reservations.v2';34/* Sample reservationDetails value:5 * {6 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",7 * "startDate": new Date("2024-12-14T15:30:00Z"),8 * "partySize": 29 * }10 */1112export const myCreateContactFunction = webMethod(Permissions.Anyone, async (reservationDetails) => {13 try {14 const createdHeldReservation = await reservations.createHeldReservation(reservationDetails);1516 const id = createdHeldReservation._id;17 const status = createdHeldReservation.status;1819 console.log('Success! Created a held reservation:', createdHeldReservation);20 return createdHeldReservation;21 } catch (error) {22 console.error(error);23 // Handle the error24 }2526});