Search.../

getReservationLocation( )

Developer Preview

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
reservationLocationId
string

ID of the ReservationLocation to retrieve.

options
Optional
GetReservationLocationOptions

An object representing the available options for retrieving a reservation location.

Returns

The retrieved reservation location.

Return Type:

Promise<
ReservationLocation
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

The date and time this reservation location was created.

_id
string

Reservation location ID.

_updatedDate
Date

The date and time this reservation location was last updated.

archived
boolean

Whether this reservation location's location is archived.

configuration
Configuration

Reservation location configuration.

default
boolean

Whether this reservation location's location is the default location of the business.

location
Location

Physical location details.

Locations can be created and configured using the Locations API or on the Business Info page in the Dashboard.

revision
string

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?

Get a reservation location (page code)

Copy Code
1import { reservationLocations } from 'wix-table-reservations-v2';
2
3// Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'
4
5reservationLocations.getReservationLocation(reservationLocationId)
6 .then((retrievedReservationLocation) => {
7 const isDefault = retrievedReservationLocation.default;
8 const minNotice = retrievedReservationLocation.configuration.onlineReservations.minimumReservationNotice;
9
10 console.log('Success! Retrieved reservation location:', retrievedReservationLocation);
11 return retrievedReservationLocation;
12 })
13 .catch((error) => {
14 console.error(error);
15 // Handle the error
16 });
17
18/* 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.77376549999999
31 * },
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": 6
64 * },
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": true
95 * },
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
Get a reservation location with options (backend)

This example demonstrates how to request the FULL fieldset in options using elevation to get the necessary permissions.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { reservationLocations } from 'wix-table-reservations.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'
6 *
7 * Sample options value:
8 * {
9 * "fieldsets": ["FULL"]
10 * }
11 */
12
13export const myGetReservationLocationFunction = webMethod(Permissions.Anyone, async (reservationLocationId, options) => {
14 const elevatedGetReservationLocation = elevate(reservationLocations.getReservationLocation);
15
16 try {
17 const result = await elevatedGetReservationLocation(reservationLocationId, options);
18 return result;
19 } catch (error) {
20 console.error(error);
21 // Handle the error
22 }
23});
24
25/* 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.77376549999999
39 * },
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": false
72 * },
73 * "partyPacing": {
74 * "number": 6,
75 * "enabled": true
76 * },
77 * "partiesSize": {
78 * "min": 1,
79 * "max": 6
80 * },
81 * "partySize": {
82 * "min": 1,
83 * "max": 6
84 * },
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": true
116 * },
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": true
130 * },
131 * {
132 * "fieldType": "START_DATE",
133 * "shown": true
134 * },
135 * {
136 * "fieldType": "END_DATE",
137 * "shown": true
138 * },
139 * {
140 * "fieldType": "CREATED_DATE",
141 * "shown": true
142 * },
143 * {
144 * "fieldType": "UPDATED_DATE",
145 * "shown": true
146 * },
147 * {
148 * "fieldType": "PARTY_SIZE",
149 * "shown": true
150 * },
151 * {
152 * "fieldType": "FIRST_NAME",
153 * "shown": true
154 * },
155 * {
156 * "fieldType": "LAST_NAME",
157 * "shown": true
158 * },
159 * {
160 * "fieldType": "EMAIL",
161 * "shown": true
162 * },
163 * {
164 * "fieldType": "PHONE",
165 * "shown": true
166 * },
167 * {
168 * "fieldType": "ADDITIONAL_INFO",
169 * "shown": true
170 * },
171 * {
172 * "fieldType": "TEAM_MESSAGE",
173 * "shown": true
174 * },
175 * {
176 * "fieldType": "STATUS",
177 * "shown": true
178 * },
179 * {
180 * "fieldType": "CUSTOM_FIELD",
181 * "customFieldId": "f4283b2d-6340-4cf9-bae7-8769e6b62127",
182 * "shown": false
183 * }
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 */
Close a restaurant and cancel all reservations on a given day

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.

Copy Code
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 */
7
8/**********************************************
9 * Backend code - reservationLocations.web.js *
10 **********************************************/
11
12import { 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';
16
17export const getRestaurantLocation = webMethod(Permissions.Anyone, async (location_id) => {
18 const elevatedGetLocation = elevate(locations.getLocation);
19
20 try {
21 const result = await elevatedGetLocation(location_id);
22 return result;
23 } catch (error) {
24 console.error(error);
25 // Handle the error
26 }
27});
28
29export const getRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, options) => {
30 const elevatedGetReservationLocations = elevate(reservationLocations.getReservationLocation);
31
32 try {
33 const result = await elevatedGetReservationLocations(reservationLocationId, options);
34 return result;
35 } catch (error) {
36 console.error(error);
37 // Handle the error
38 }
39});
40
41export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {
42 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);
43
44 try {
45 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);
46 return result;
47 } catch (error) {
48 console.error(error);
49 // Handle the error
50 }
51});
52
53/*******************************************
54 * Backend code - reservations.web.js *
55 *******************************************/
56
57import { Permissions, webMethod } from 'wix-web-module';
58import { reservations } from 'wix-table-reservations.v2';
59import { elevate } from 'wix-auth';
60
61export const queryReservationsInDateRange = webMethod(Permissions.Anyone, async (startDate, endDate) => {
62 const elevatedQueryReservations = elevate(reservations.queryReservations);
63
64 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 error
73 }
74});
75
76/*************
77 * Page code *
78 *************/
79
80import { reservationLocations } from 'wix-table-reservations.v2';
81import { reservations } from 'wix-table-reservations.v2';
82
83import { 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';
87
88
89$w.onReady(async function () {
90 $w('#datePicker').hide();
91 $w('#confirmButton').hide();
92 $w('#cancellationNotice').hide();
93
94 // Set the earliest selectable date to the day after the current date
95 var tomorrowsDate = new Date();
96 tomorrowsDate.setDate(tomorrowsDate.getDate() + 1);
97 $w('#datePicker').minDate = tomorrowsDate;
98 $w('#datePicker').value = tomorrowsDate;
99
100 //Get the list of reservation locations
101 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 error
108 }
109 })();
110
111 //Create an array to hold names and values for our dropdown list
112 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` service
115 const locationObject = await getRestaurantLocation(myReservationLocationList[object].location._id);
116 dropdownOptions.push({
117 "label": locationObject.name,
118 "value": myReservationLocationList[object]._id
119 })
120 }
121 //Populate our dropdown list with the array
122 $w("#locationDropdown").options = dropdownOptions;
123
124 $w('#locationDropdown').onChange( (event) => {
125 if ($w('#locationDropdown').value) {
126 $w('#datePicker').show();
127 $w('#confirmButton').show();
128 }
129 });
130
131 $w('#confirmButton').onClick( async (event) => {
132 const options = {
133 "fieldsets": "FULL"
134 }
135 const selectedLocation = await getRestaurantDetails($w('#locationDropdown').value, options)
136
137 //Create a new special hour period to push to the list in our reservation location's business schedule
138 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": true
145 }
146
147 if(!("businessSchedule" in selectedLocation.configuration.onlineReservations)){
148 //Handle business schedule configuration
149 }
150 selectedLocation.configuration.onlineReservations.businessSchedule.specialHourPeriod.push(mySpecialHourPeriod);
151
152 await updateRestaurantDetails(selectedLocation._id, selectedLocation);
153
154 //Create a variable to hold of names and phone numbers of canceled reservations.
155 let canceledReservationsNote = "Notify of cancellation:\n";
156
157 //Query for reservations on the selected date and cancel any at our selected reservation location
158 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.phone
163 }
164
165 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 error
171 return false;
172 }
173 })();
174
175 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 }
182
183 $w('#cancellationNotice').text = canceledReservationsNote;
184 $w('#cancellationNotice').show();
185 });
186});
187