Search.../

createReservation( )

Developer Preview

Creates a new reservation.

Description

createReservation() accepts and requires different fields depending on the status provided and your permissions.

Status and source

If a status is not provided, it will be set to:

  • RESERVED if manual approval is not required for confirmation
  • REQUESTED if manual approval is required for confirmation.

A reservation created with any source other than WALK_IN requires the reservation.reservee.phone and reservation.reservee.firstName fields. Attempting to create a reservation without these fields will result in an error.

Permissions

Including the fields status, source, reservation.details.tableIds, reservation.details.endDate, ignoreReservationLocationConflicts, or ignoreTableCombinationConflicts in the request requires additional permissions. See this API's Introduction article for more information.

If source is not provided, its value is set depending on the permissions of the user making the call. See this API's Introduction article for more information.

Note: createReservation() requires all details of the reservation upfront. The process of creating a reservation can be broken up using createHeldReservation. createHeldReservation creates a temporary reservation that expires automatically unless it is completed with the addition of more details using reserveReservation().

Syntax

function createReservation(reservation: Reservation, options: CreateReservationOptions): Promise<Reservation>

createReservation Parameters

NAME
TYPE
DESCRIPTION
reservation
Reservation

Reservation details.

options
Optional
CreateReservationOptions

Options for creating the reservation.

Returns

Reservation.

Return Type:

Promise<
Reservation
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the reservation was created.

_id
string

Reservation ID.

_updatedDate
Date

Date and time the reservation was changed.

declineReason
string

The reason the reservation was declined.

details
Details

Reservation details.

reservedBy
ReservedBy

Information about the person making the reservation.

This field is required if the reservation's status is anything other than WALK_IN.

reservee
Reservee

Information about the person the reservation is being made for.

A reservation created with any source other than WALK_IN requires the reservation.reservee.phone and reservation.reservee.firstName fields. Attempting to create a reservation without these fields results in an error.

revision
string

Revision number, which increments by 1 each time the reservation is updated. To prevent conflicting changes, the current revision must be passed when updating the reservation.

Ignored when creating a reservation.

source
string

Reservation source.

This indicates how the reservation was made.

  • ONLINE indicates that the customer made the reservation through a website or app.
  • OFFLINE indicates that the reservation was made by a restaurant employee, for example when a customer calls to make a reservation.
  • WALK-IN indicates that the customer did not make a reservation beforehand, and the reservation was entered into the system by a restaurant employee when the customer arrived at the restaurant.
status
string

Status of the reservation.

Supported values:

  • HELD: The reservation is temporary and will expire in 10 minutes if its status isn’t changed. This phase temporarily reserves the required number of seats and tables for a given party size at a chosen time while a customer enters details and/or confirms their reservation request.
  • REQUESTED: A customer finished requesting this reservation, meaning they have added all necessary details and confirmed the request. Restaurant staff can now either approve or decline the reservation request.
  • DECLINED: The restaurant’s owner or staff declined the customer’s request to make the reservation.
  • RESERVED: The reservation is confirmed.
  • SEATED: The customer is currently occupying the table.
  • CANCELED: The reservation is canceled.
  • NO_SHOW: The customer didn't show up for their reservation.
  • FINISHED: The reservation completed successfully.

See the article for this API titled "The Reservation Lifecycle" in the menu on the left for more details on each of the statuses, and an explanation of the reservation lifecycle.

teamMessage
string

Team message.

A message for the restaurant staff containing any additional information regarding the reservation, such as special requirements for the guests.

Was this helpful?

Create a basic reservation (page code)

Copy Code
1import { reservations } from 'wix-table-reservations.v2';
2
3/* Sample reservation value:
4 * {
5 * "details": {
6 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",
7 * "startDate": new Date("2024-12-18T15:30:00Z"),
8 * "partySize": 2
9 * },
10 * "reservee":{
11 * "phone":"+972555555555",
12 * "firstName": "John"
13 * },
14 * }
15 */
16
17reservations.createReservation(reservation)
18 .then((createdReservation) => {
19 const id = createdReservation._id;
20 const status = createdReservation.status;
21
22 console.log('Success! Created a reservation:', createdReservation);
23 return createdReservation;
24 })
25 .catch((error) => {
26 console.error(error);
27 // Handle the error
28 });
29
30/* Promise resolves to:
31 * {
32 * "reservation": {
33 * "status": "RESERVED",
34 * "source": "UNKNOWN",
35 * "details": {
36 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",
37 * "tableIds": [],
38 * "startDate": "2024-12-16T15:30:00.000Z",
39 * "endDate": "2024-12-16T17:00:00.000Z",
40 * "partySize": 2
41 * },
42 * "revision": "1",
43 * "migrationNotes": [],
44 * "tablesWithReservationConflicts": [],
45 * "_id": "d9f15462-a46a-45df-8b0f-2ef557f94ca9",
46 * "_createdDate": "2024-01-17T07:58:17.339Z"
47 * }
48 * }
49 */
50
Create a reservation with options (backend)

This function call requires elevation to get the necessary permissions.

Copy Code
1import { reservations } from 'wix-table-reservations.v2';
2import { elevate } from 'wix-auth';
3import { Permissions, webMethod } from 'wix-web-module';
4
5/* Sample reservation value:
6 * {
7 * "details": {
8 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",
9 * "startDate": new Date("2024-12-15T10:30:00Z"),
10 * "partySize": 2
11 * },
12 * "reservee":{
13 * "phone":"+972555555555",
14 * "firstName": "John"
15 * },
16 * "teamMessage": "Make sure the table has bottled water"
17 * }
18 *
19 * Sample options value:
20 * {
21 * "ignoreTableCombinationConflicts":["RESERVED", "TOO_BIG"],
22 * "ignoreReservationLocationConflicts":["PARTY_PACING"]
23 * }
24 */
25
26export const myCreateReservationFunction = webMethod(Permissions.Anyone, async (reservation, options) => {
27 const elevatedCreateReservation = elevate(reservations.createReservation);
28
29 try {
30 const result = await elevatedCreateReservation(reservation, options);
31 return result;
32 } catch (error) {
33 console.error(error);
34 // Handle the error
35 }
36});
37
38/* Promise resolves to:
39 * {
40 * "status": "RESERVED",
41 * "source": "UNKNOWN",
42 * "details": {
43 * "reservationLocationId": "fab8cc1f-31cf-462f-b5bb-392594624bf2",
44 * "tableIds": [
45 * "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
46 * ],
47 * "startDate": "2024-12-15T10:30:00.000Z",
48 * "endDate": "2024-12-15T12:00:00.000Z",
49 * "partySize": 2
50 * },
51 * "reservee": {
52 * "firstName": "John",
53 * "phone": "+972555555555",
54 * "contactId": "e8396cd4-1398-4886-a0ca-82647ff0ccaf"
55 * },
56 * "teamMessage": "make sure the table has bottled water",
57 * "revision": "1",
58 * "migrationNotes": [],
59 * "tablesWithReservationConflicts": [],
60 * "_id": "586db492-986e-4849-9ef9-100f0ffa4321",
61 * "_createdDate": "2024-01-17T09:46:43.844Z",
62 * "_updatedDate": "2024-01-17T09:46:43.844Z"
63 * }
64 */