getReservationLocation( )
Retrieves a reservation location by ID.
Description
The FULL
fieldset can only be retrieved by users with the READ RESERVATION LOCATIONS (FULL)
or MANAGE RESERVATION LOCATIONS
permission scopes.
Syntax
function getReservationLocation(reservationLocationId: string, options: GetReservationLocationOptions): Promise<ReservationLocation>
getReservationLocation Parameters
NAME
TYPE
DESCRIPTION
ID of the ReservationLocation to retrieve.
An object representing the available options for retrieving a reservation location.
Returns
The retrieved reservation location.
Return Type:
NAME
TYPE
DESCRIPTION
The date and time this reservation location was created.
Reservation location ID.
The date and time this reservation location was last updated.
Whether this reservation location's location
is archived.
Reservation location configuration.
Whether this reservation location's location
is the default location of the business.
Physical location details.
Locations can be created and configured using the Locations API or on the Business Info page in the Dashboard.
Represents the current state of a reservation location. Each time the reservation location is modified, its revision
changes. For an update operation to succeed, you must pass the latest revision.
Was this helpful?
1import { reservationLocations } from 'wix-table-reservations-v2';23// Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'45reservationLocations.getReservationLocation(reservationLocationId)6 .then((retrievedReservationLocation) => {7 const isDefault = retrievedReservationLocation.default;8 const minNotice = retrievedReservationLocation.configuration.onlineReservations.minimumReservationNotice;910 console.log('Success! Retrieved reservation location:', retrievedReservationLocation);11 return retrievedReservationLocation;12 })13 .catch((error) => {14 console.error(error);15 // Handle the error16 });1718/* Promise resolves to:19 * {20 * "location": {21 * "name": "Nemal Tel Aviv Street",22 * "fax": "",23 * "timeZone": "Europe/Dublin",24 * "email": "",25 * "phone": "",26 * "address": {27 * "formatted": "Tel Aviv Port, Nemal Tel Aviv Street, Tel Aviv, Israel",28 * "location": {29 * "latitude": 32.0972612,30 * "longitude": 34.7737654999999931 * },32 * "streetAddress": {33 * "name": "Nemal Tel Aviv Street",34 * "number": "",35 * "apt": ""36 * },37 * "city": "Tel Aviv-Yafo",38 * "country": "IL"39 * },40 * "businessSchedule": {41 * "periods": [42 * {43 * "openDay": "SUNDAY",44 * "openTime": "00:00",45 * "closeDay": "MONDAY",46 * "closeTime": "00:00"47 * },48 * {49 * "openDay": "THURSDAY",50 * "openTime": "00:00",51 * "closeDay": "SUNDAY",52 * "closeTime": "00:00"53 * }54 * ],55 * "specialHourPeriod": []56 * },57 * "_id": "f1f59093-6842-45a4-b9d1-106429ec8313"58 * },59 * "configuration": {60 * "onlineReservations": {61 * "partiesSize": {62 * "min": 1,63 * "max": 664 * },65 * "minimumReservationNotice": {66 * "number": 30,67 * "unit": "MINUTES"68 * },69 * "turnoverTimeRules": [],70 * "turnoverRules": [],71 * "businessSchedule": {72 * "periods": [73 * {74 * "openDay": "SUNDAY",75 * "openTime": "00:00",76 * "closeDay": "TUESDAY",77 * "closeTime": "00:00"78 * },79 * {80 * "openDay": "WEDNESDAY",81 * "openTime": "00:00",82 * "closeDay": "THURSDAY",83 * "closeTime": "00:00"84 * },85 * {86 * "openDay": "FRIDAY",87 * "openTime": "00:00",88 * "closeDay": "SUNDAY",89 * "closeTime": "00:00"90 * }91 * ],92 * "specialHourPeriod": []93 * },94 * "onlineReservationsEnabled": true95 * },96 * "reservationForm": {97 * "customFieldDefinitions": [98 * {99 * "name": "Allergies",100 * "required": false,101 * "_id": "f4283b2d-6340-4cf9-bae7-8769e6b62127"102 * }103 * ]104 * },105 * "myReservationsFields": []106 * },107 * "default": true,108 * "archived": false,109 * "_id": "fab8cc1f-31cf-462f-b5bb-392594624bf2"110 * }111 */112
This example demonstrates how to request the FULL
fieldset in options
using elevation to get the necessary permissions.
1import { Permissions, webMethod } from 'wix-web-module';2import { reservationLocations } from 'wix-table-reservations.v2';3import { elevate } from 'wix-auth';45/* Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'6 *7 * Sample options value:8 * {9 * "fieldsets": ["FULL"]10 * }11 */1213export const myGetReservationLocationFunction = webMethod(Permissions.Anyone, async (reservationLocationId, options) => {14 const elevatedGetReservationLocation = elevate(reservationLocations.getReservationLocation);1516 try {17 const result = await elevatedGetReservationLocation(reservationLocationId, options);18 return result;19 } catch (error) {20 console.error(error);21 // Handle the error22 }23});2425/* Promise resolves to:26 * {27 * "revision": "10",28 * "location": {29 * "name": "Nemal Tel Aviv Street",30 * "fax": "",31 * "timeZone": "Europe/Dublin",32 * "email": "",33 * "phone": "",34 * "address": {35 * "formatted": "Tel Aviv Port, Nemal Tel Aviv Street, Tel Aviv, Israel",36 * "location": {37 * "latitude": 32.0972612,38 * "longitude": 34.7737654999999939 * },40 * "streetAddress": {41 * "name": "Nemal Tel Aviv Street",42 * "number": "",43 * "apt": ""44 * },45 * "city": "Tel Aviv-Yafo",46 * "country": "IL"47 * },48 * "businessSchedule": {49 * "periods": [50 * {51 * "openDay": "SUNDAY",52 * "openTime": "00:00",53 * "closeDay": "MONDAY",54 * "closeTime": "00:00"55 * },56 * {57 * "openDay": "THURSDAY",58 * "openTime": "00:00",59 * "closeDay": "SUNDAY",60 * "closeTime": "00:00"61 * }62 * ],63 * "specialHourPeriod": []64 * },65 * "_id": "f1f59093-6842-45a4-b9d1-106429ec8313"66 * },67 * "configuration": {68 * "onlineReservations": {69 * "seatPacing": {70 * "number": 11,71 * "enabled": false72 * },73 * "partyPacing": {74 * "number": 6,75 * "enabled": true76 * },77 * "partiesSize": {78 * "min": 1,79 * "max": 680 * },81 * "partySize": {82 * "min": 1,83 * "max": 684 * },85 * "minimumReservationNotice": {86 * "number": 30,87 * "unit": "MINUTES"88 * },89 * "defaultTurnoverTime": 90,90 * "turnoverTimeRules": [],91 * "turnoverRules": [],92 * "businessSchedule": {93 * "periods": [94 * {95 * "openDay": "SUNDAY",96 * "openTime": "00:00",97 * "closeDay": "TUESDAY",98 * "closeTime": "00:00"99 * },100 * {101 * "openDay": "WEDNESDAY",102 * "openTime": "00:00",103 * "closeDay": "THURSDAY",104 * "closeTime": "00:00"105 * },106 * {107 * "openDay": "FRIDAY",108 * "openTime": "00:00",109 * "closeDay": "SUNDAY",110 * "closeTime": "00:00"111 * }112 * ],113 * "specialHourPeriod": []114 * },115 * "onlineReservationsEnabled": true116 * },117 * "reservationForm": {118 * "customFieldDefinitions": [119 * {120 * "name": "Allergies",121 * "required": false,122 * "_id": "f4283b2d-6340-4cf9-bae7-8769e6b62127"123 * }124 * ]125 * },126 * "myReservationsFields": [127 * {128 * "fieldType": "TABLE",129 * "shown": true130 * },131 * {132 * "fieldType": "START_DATE",133 * "shown": true134 * },135 * {136 * "fieldType": "END_DATE",137 * "shown": true138 * },139 * {140 * "fieldType": "CREATED_DATE",141 * "shown": true142 * },143 * {144 * "fieldType": "UPDATED_DATE",145 * "shown": true146 * },147 * {148 * "fieldType": "PARTY_SIZE",149 * "shown": true150 * },151 * {152 * "fieldType": "FIRST_NAME",153 * "shown": true154 * },155 * {156 * "fieldType": "LAST_NAME",157 * "shown": true158 * },159 * {160 * "fieldType": "EMAIL",161 * "shown": true162 * },163 * {164 * "fieldType": "PHONE",165 * "shown": true166 * },167 * {168 * "fieldType": "ADDITIONAL_INFO",169 * "shown": true170 * },171 * {172 * "fieldType": "TEAM_MESSAGE",173 * "shown": true174 * },175 * {176 * "fieldType": "STATUS",177 * "shown": true178 * },179 * {180 * "fieldType": "CUSTOM_FIELD",181 * "customFieldId": "f4283b2d-6340-4cf9-bae7-8769e6b62127",182 * "shown": false183 * }184 * ],185 * "tableManagement": {186 * "tableDefinitions": [187 * {188 * "name": "Small table",189 * "seatsMin": 1,190 * "seatsMax": 4,191 * "isActive": true,192 * "_id": "1ed802ae-708f-4da6-9177-54c3df5d3dd5"193 * },194 * {195 * "name": "Big table",196 * "seatsMin": 3,197 * "seatsMax": 6,198 * "isActive": true,199 * "_id": "2c8aed3a-20c5-404c-b075-84a92f90a996"200 * }201 * ],202 * "deletedTableDefinitions": [],203 * "tableCombinations": [204 * {205 * "tableIds": [206 * "1ed802ae-708f-4da6-9177-54c3df5d3dd5",207 * "2c8aed3a-20c5-404c-b075-84a92f90a996"208 * ],209 * "seatsMin": 7,210 * "seatsMax": 10,211 * "isActive": true,212 * "_id": "6df9a875-d30d-4c0f-9faa-0a5ae18cd6f6"213 * }214 * ]215 * }216 * },217 * "default": true,218 * "archived": false,219 * "_id": "fab8cc1f-31cf-462f-b5bb-392594624bf2",220 * "_createdDate": "2023-07-10T09:06:07.507Z",221 * "_updatedDate": "2024-01-09T12:42:12.840Z"222 * }223 */
This scenario sets up an interface that allows a site owner to select a reservation location and a date, and then close the restaurant on that date. We start by creating a day-long special hour period during which reservations can't be made. We then cancel all reservations on that date.
1/* This example requires the following elements:2 * A dropdown element named `locationDropdown`.3 * A date picker element named 'datePicker`.4 * A button named `confirmButton`.5 * A text element named `cancellationNotice`.6 */78/**********************************************9 * Backend code - reservationLocations.web.js *10 **********************************************/1112import { Permissions, webMethod } from 'wix-web-module';13import { reservationLocations } from 'wix-table-reservations.v2';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});2829export const getRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, options) => {30 const elevatedGetReservationLocations = elevate(reservationLocations.getReservationLocation);3132 try {33 const result = await elevatedGetReservationLocations(reservationLocationId, options);34 return result;35 } catch (error) {36 console.error(error);37 // Handle the error38 }39});4041export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {42 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);4344 try {45 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);46 return result;47 } catch (error) {48 console.error(error);49 // Handle the error50 }51});5253/*******************************************54 * Backend code - reservations.web.js *55 *******************************************/5657import { Permissions, webMethod } from 'wix-web-module';58import { reservations } from 'wix-table-reservations.v2';59import { elevate } from 'wix-auth';6061export const queryReservationsInDateRange = webMethod(Permissions.Anyone, async (startDate, endDate) => {62 const elevatedQueryReservations = elevate(reservations.queryReservations);6364 try {65 const result = await elevatedQueryReservations()66 .ge('details.startDate', startDate)67 .lt('details.startDate', endDate)68 .find();69 return result;70 } catch (error) {71 console.error(error);72 // Handle the error73 }74});7576/*************77 * Page code *78 *************/7980import { reservationLocations } from 'wix-table-reservations.v2';81import { reservations } from 'wix-table-reservations.v2';8283import { getRestaurantLocation } from 'backend/reservationLocations.web.js';84import { getRestaurantDetails } from 'backend/reservationLocations.web.js';85import { updateRestaurantDetails } from 'backend/reservationLocations.web.js';86import { queryReservationsInDateRange } from 'backend/reservations.web.js';878889$w.onReady(async function () {90 $w('#datePicker').hide();91 $w('#confirmButton').hide();92 $w('#cancellationNotice').hide();9394 // Set the earliest selectable date to the day after the current date95 var tomorrowsDate = new Date();96 tomorrowsDate.setDate(tomorrowsDate.getDate() + 1);97 $w('#datePicker').minDate = tomorrowsDate;98 $w('#datePicker').value = tomorrowsDate;99100 //Get the list of reservation locations101 const myReservationLocationList = await (async () => {102 try {103 let fullListObject = await reservationLocations.listReservationLocations();104 return fullListObject.reservationLocations;105 } catch (error) {106 console.error(error);107 // Handle the error108 }109 })();110111 //Create an array to hold names and values for our dropdown list112 let dropdownOptions = [];113 for (const object in myReservationLocationList){114 //Use the _id stored in the reservation location's location object to get the location's name from the `locations` service115 const locationObject = await getRestaurantLocation(myReservationLocationList[object].location._id);116 dropdownOptions.push({117 "label": locationObject.name,118 "value": myReservationLocationList[object]._id119 })120 }121 //Populate our dropdown list with the array122 $w("#locationDropdown").options = dropdownOptions;123124 $w('#locationDropdown').onChange( (event) => {125 if ($w('#locationDropdown').value) {126 $w('#datePicker').show();127 $w('#confirmButton').show();128 }129 });130131 $w('#confirmButton').onClick( async (event) => {132 const options = {133 "fieldsets": "FULL"134 }135 const selectedLocation = await getRestaurantDetails($w('#locationDropdown').value, options)136137 //Create a new special hour period to push to the list in our reservation location's business schedule138 const selectedDate = $w('#datePicker').value;139 const dayAfterSelectedDate = new Date(selectedDate);140 dayAfterSelectedDate.setDate(selectedDate.getDate() + 1);141 const mySpecialHourPeriod = {142 "startDate": selectedDate,143 "endDate": dayAfterSelectedDate,144 "isClosed": true145 }146147 if(!("businessSchedule" in selectedLocation.configuration.onlineReservations)){148 //Handle business schedule configuration149 }150 selectedLocation.configuration.onlineReservations.businessSchedule.specialHourPeriod.push(mySpecialHourPeriod);151152 await updateRestaurantDetails(selectedLocation._id, selectedLocation);153154 //Create a variable to hold of names and phone numbers of canceled reservations.155 let canceledReservationsNote = "Notify of cancellation:\n";156157 //Query for reservations on the selected date and cancel any at our selected reservation location158 let reservationsOnSelectedDate = await queryReservationsInDateRange(selectedDate, dayAfterSelectedDate);159 for(let reservation in reservationsOnSelectedDate._items){160 if(reservationsOnSelectedDate._items[reservation].details.reservationLocationId == selectedLocation._id){161 let options = {162 "phone" : reservationsOnSelectedDate._items[reservation].reservee.phone163 }164165 const canceledReservation = await (async () => {166 try {167 return reservations.cancelReservation(reservationsOnSelectedDate._items[reservation]._id, reservationsOnSelectedDate._items[reservation].revision, options)168 } catch (error) {169 console.error(error);170 // Handle the error171 return false;172 }173 })();174175 if(canceledReservation){176 canceledReservationsNote += "First name: " + reservationsOnSelectedDate._items[reservation].reservee.firstName +177 ". Last name: " + reservationsOnSelectedDate._items[reservation].reservee.lastName +178 ". Phone: " + reservationsOnSelectedDate._items[reservation].reservee.phone + "\n";179 }180 }181 }182183 $w('#cancellationNotice').text = canceledReservationsNote;184 $w('#cancellationNotice').show();185 });186});187