> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# GetTimeSlots

# Package: reservations

# Namespace: TimeSlotsService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/restaurants/reservations/time-slots/get-time-slots.md

## Permission Scopes:
Manage Reservations (Basic): SCOPE.DC-RESERVATIONS.MANAGE-RESERVATIONS-BASIC

## Introduction

Returns a list of time slots at a specified reservation location on a specified `date`, and their availability for a specified `partySize`.

Without passing optional parameters, the list will contain a single time slot at the specified `date`.
Use `slotsBefore` and `slotsAfter` to get additional time slots before and after the specified `date`.

If you do not provide a `duration`, the duration will be calculated automatically based on the reservation location's configuration.
The reservation location's settings used to determine the duration are its `defaultTurnoverTime` and `turnoverTimeRules`. These specify how much time should be allotted for a reservation of a party of a specified size.

The interval between `startDate`s of time slots in the response is determined by the reservation location's `timeSlotInterval`. This interval is not affected by the `duration` provided.

---

## REST API

### Schema

```
 Method: getTimeSlots
 Description: Returns a list of time slots at a specified reservation location on a specified `date`, and their availability for a specified `partySize`.  Without passing optional parameters, the list will contain a single time slot at the specified `date`. Use `slotsBefore` and `slotsAfter` to get additional time slots before and after the specified `date`.  If you do not provide a `duration`, the duration will be calculated automatically based on the reservation location's configuration. The reservation location's settings used to determine the duration are its `defaultTurnoverTime` and `turnoverTimeRules`. These specify how much time should be allotted for a reservation of a party of a specified size.  The interval between `startDate`s of time slots in the response is determined by the reservation location's `timeSlotInterval`. This interval is not affected by the `duration` provided.
 URL: https://www.wixapis.com/table-reservations/reservations/v1/time-slots
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  reservationLocationId, date, partySize
 Method parameters: 
   param name: date | type: date | description: Date and time for which to retrieve a time slot in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#coordinated_Universal_Time_(UTC)) format. | required: true | validation: format date-time
   param name: duration | type: duration | description: Duration in minutes of the time slot.  Min: `5`  | validation: minimum 5, maximum 1000, format int32
   param name: partySize | type: partySize | description: Size of the party that needs to be seated during this time slot.  Min: `1` | required: true | validation: minimum 1, maximum 10000, format int32
   param name: reservationLocationId | type: reservationLocationId | description: GUID of the reservation location for which to retrieve time slots. | required: true | validation: format GUID
   param name: slotsAfter | type: slotsAfter | description: The number of time slots to retrieve after the specified `date`.  | validation: minimum 0, maximum 50, format int32
   param name: slotsBefore | type: slotsBefore | description: The number of time slots to retrieve before the specified `date`.  | validation: minimum 0, maximum 50, format int32
 Return type: GetTimeSlotsResponse
  - name: timeSlots | type: array<TimeSlot> | description: A list of time slots and their availability according to the specified party size.  
     - name: startDate | type: string | description: Start date and time of this time slot.  | validation: format date-time
     - name: duration | type: integer | description: Duration in minutes of this time slot.  
     - name: status | type: Status | description: Availability status of this time slot.  
         - enum:
         -     AVAILABLE: The restaurant can accommodate a party of the given size in this time slot.
         -     UNAVAILABLE: The restaurant can't accommodate a party of the given size in this time slot.
         -     NON_WORKING_HOURS: The restaurant is not open during this time slot. Time slots retrieved by Get Scheduled Time Slots never have this status.
     - name: manualApproval | type: boolean | description: Whether manual approval is required to make a reservation in this time slot.  


```

### Examples

### Get time slots
```curl
curl -X POST 'https://www.wixapis.com/table-reservations/reservations/v1/time-slots' \
    -H 'Authorization: <AUTH>' \
    --data-binary '{"slotsBefore":7,"slotsAfter":7,"date":"2023-06-08T11:30:00.000Z","partySize":2,"reservationLocationId":"b3d165aa-52bb-49bb-a3e4-a673d9a1cb9d"}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.tableReservations.timeSlots.getTimeSlots(reservationLocationId, date, partySize, options)
 Description: Returns a list of time slots at a specified reservation location on a specified `date`, and their availability for a specified `partySize`.  Without passing optional parameters, the list will contain a single time slot at the specified `date`. Use `slotsBefore` and `slotsAfter` to get additional time slots before and after the specified `date`.  If you do not provide a `duration`, the duration will be calculated automatically based on the reservation location's configuration. The reservation location's settings used to determine the duration are its `defaultTurnoverTime` and `turnoverTimeRules`. These specify how much time should be allotted for a reservation of a party of a specified size.  The interval between `startDate`s of time slots in the response is determined by the reservation location's `timeSlotInterval`. This interval is not affected by the `duration` provided.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  reservationLocationId, date, partySize
 Method parameters: 
   param name: reservationLocationId | type: string | description: GUID of the reservation location for which to retrieve time slots. | required: true | validation: format GUID
   param name: date | type: string | description: Date and time for which to retrieve a time slot in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#coordinated_Universal_Time_(UTC)) format. | required: true | validation: format date-time
   param name: partySize | type: integer | description: Size of the party that needs to be seated during this time slot.  Min: `1` | required: true | validation: minimum 1, maximum 10000, format int32
   param name: options | type: GetTimeSlotsOptions  none  
        - name: duration | type: integer | description: Duration in minutes of the time slot.  Min: `5`  | validation: minimum 5, maximum 1000, format int32
        - name: slotsBefore | type: integer | description: The number of time slots to retrieve before the specified `date`.  | validation: minimum 0, maximum 50, format int32
        - name: slotsAfter | type: integer | description: The number of time slots to retrieve after the specified `date`.  | validation: minimum 0, maximum 50, format int32
 Return type: PROMISE<GetTimeSlotsResponse>
  - name: timeSlots | type: array<TimeSlot> | description: A list of time slots and their availability according to the specified party size.  
     - name: startDate | type: Date | description: Start date and time of this time slot.  
     - name: duration | type: integer | description: Duration in minutes of this time slot.  
     - name: status | type: Status | description: Availability status of this time slot.  
         - enum:
         -     AVAILABLE: The restaurant can accommodate a party of the given size in this time slot.
         -     UNAVAILABLE: The restaurant can't accommodate a party of the given size in this time slot.
         -     NON_WORKING_HOURS: The restaurant is not open during this time slot. Time slots retrieved by Get Scheduled Time Slots never have this status.
     - name: manualApproval | type: boolean | description: Whether manual approval is required to make a reservation in this time slot.  


```

### Examples

### Create a held reservation with a given time, location, and party size (with $w)
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.

```javascript
/* This example requires the following elements:
 * A dropdown element named `locationDropdown`.
 * A dropdown element named `partySizeDropdown`.
 * A dropdown element named `timeSlotDropdown`.
 * A button named `confirmButton`.
 * A text element named `heldReservationNotification`.
 */

/*************************************************
 * Backend code - reservationLocations.web.js/ts *
 ************************************************/

import { Permissions, webMethod } from '@wix/web-methods';
import { locations } from '@wix/business-tools';
import { auth } from '@wix/essentials';

export const getRestaurantLocation = webMethod(Permissions.Anyone, async (location_id) => {
  const elevatedGetLocation = auth.elevate(locations.getLocation);

  try {
     const result = await elevatedGetLocation(location_id);
     return result;
   } catch (error) {
     console.error(error);
     // Handle the error
   }
});

/*************
 * Page code *
 *************/

import { reservationLocations } from '@wix/table-reservations';
import { reservations } from '@wix/table-reservations';
import { timeSlots } from '@wix/table-reservations';

import { getRestaurantLocation } from 'backend/reservationLocations.web';

$w.onReady(async function () {
  $w('#timeSlotDropdown').hide();
  $w('#partySizeDropdown').hide();
  $w('#confirmButton').hide();
  $w('#heldReservationNotification').hide();

  //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 locations dropdown list
  let locationDropdownOptions = [];
  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);
    locationDropdownOptions.push({
      "label": locationObject.name, 
      "value": myReservationLocationList[object]._id
    })	
  }
  //Populate our dropdown list with the array
  $w("#locationDropdown").options = locationDropdownOptions;

  //Create an array to hold numbers and values for our party size dropdown list
  let partySizeDropdownOptions = [];
  for (let i = 1; i<10; i++){
    partySizeDropdownOptions.push({
      "label": String(i), 
      "value": String(i)
    })	
  }
  //Populate our dropdown list with the array
  $w("#partySizeDropdown").options = partySizeDropdownOptions;

  $w('#locationDropdown').onChange( (event) => {
    if ($w('#locationDropdown').value) {
      $w('#partySizeDropdown').show();
      $w('#timeSlotDropdown').hide()
      $w('#confirmButton').hide();
    }
  });

  $w('#partySizeDropdown').onChange( async (event) => {
    if ($w('#locationDropdown').value) {
      $w('#timeSlotDropdown').show()
      $w('#confirmButton').hide();

      const timeSlotDetails = {
        "reservationLocationId": $w('#locationDropdown').value, 
        "date": new Date(),
        "partySize": parseInt($w('#partySizeDropdown').value)
      };

      const timeSlotOptions = {
        "duration": 30,
	"slotsAfter": 8,
	"slotsBefore": 0
      };

      //Get the list of time slots according to the details and options above
      const availableTimeSlots = await (async () => {
        try {
          let fullListObject = await timeSlots.getTimeSlots(timeSlotDetails.reservationLocationId, timeSlotDetails.date, timeSlotDetails.partySize, timeSlotOptions);
          return fullListObject.timeSlots;
        } catch (error) {
          console.error(error);
          // Handle the error
        }
      })();

      //Create an array to hold numbers and values for our time slot dropdown list
      let timeSlotDropdownOptions = [];
      for (const timeSlot in availableTimeSlots){
        if(availableTimeSlots[timeSlot].status == "AVAILABLE"){
          timeSlotDropdownOptions.push({
            "label": String(availableTimeSlots[timeSlot].startDate), 
            "value": String(availableTimeSlots[timeSlot].startDate)
          })
        }	
      }
      //Populate our dropdown list with the array
      $w("#timeSlotDropdown").options = timeSlotDropdownOptions;
    }
  });

  $w('#timeSlotDropdown').onChange( async (event) => {
    if ($w('#timeSlotDropdown').value) {
      $w('#confirmButton').show();
    }
  });

  $w('#confirmButton').onClick( async (event) => {
    //Get the list of time slots according to the details and options above
    
    const createdHeldReservation = await (async () => {
      try {
        const reservationDetails = {
          "reservationLocationId": $w('#locationDropdown').value, 
          "startDate": new Date($w("#timeSlotDropdown").value),
          "partySize": parseInt($w('#partySizeDropdown').value)
        };

        return await reservations.createHeldReservation(reservationDetails);
      } catch (error) {
        console.error(error);
        // Handle the error
      }
    })();

    if(createdHeldReservation){
      $w('#heldReservationNotification').text = "Held reservation created successfully."
      $w('#heldReservationNotification').show();
    }
  });
});

```

### Get time slots with options
This example gets a 5-minute time slot at the selected date, and the next 5-minute time slot after it.

```javascript
import { timeSlots } from '@wix/table-reservations';

/* Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'
 * Sample date value: new Date("2023-12-29T12:30:00Z")
 * Sample partySize value: 2
 * 
 * Sample options value: 
 * {
 *   "duration": 5,
 *   "slotsAfter": 1,
 *   "slotsBefore": 0
 * }
 */

timeSlots.getTimeSlots(reservationLocationId, new Date("2023-12-29T12:30:00Z"), partySize)
  .then((retrievedSlots) => {
    const firstStartDate = retrievedSlots.timeSlots[0].startDate;
    const firstStatus = retrievedSlots.timeSlots[0].status;

    console.log('Success! Retrieved the following time slots:', retrievedSlots);
    return retrievedSlots;
  })
  .catch((error) => {
    console.error(error);
    // Handle the error
  });

/* Promise resolves to:
* {
*   "timeSlots": [
*     {
*       "startDate": "2023-12-29T12:30:00.000Z",
*       "duration": 5,
*       "status": "UNAVAILABLE",
*       "tableCombinations": [],
*       "manualApproval": false
*     },
*     {
*       "startDate": "2023-12-29T12:45:00.000Z",
*       "duration": 5,
*       "status": "UNAVAILABLE",
*       "tableCombinations": [],
*       "manualApproval": false
*     }
*   ]
* }
*/
```

### Get time slots for a given date,location, and party size
Retrieves the time slots around a given date for a reservation location and party size.

```javascript
import { timeSlots } from '@wix/table-reservations';

/* Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'
 * Sample date value: new Date("2023-12-29T12:30:00Z")
 * Sample partySize value: 2
 */

timeSlots.getTimeSlots(reservationLocationId, new Date("2023-12-29T12:30:00Z"), partySize)
  .then((retrievedSlots) => {
    const firstStartDate = retrievedSlots.timeSlots[0].startDate;
    const firstStatus = retrievedSlots.timeSlots[0].status;

    console.log('Success! Retrieved the following time slots:', retrievedSlots);
    return retrievedSlots;
  })
  .catch((error) => {
    console.error(error);
    // Handle the error
  });

/* Promise resolves to:
 * {
 *   "timeSlots": [
 *     {
 *       "startDate": "2023-12-29T10:00:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T10:15:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T10:30:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T10:45:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *   },
 *     {
 *       "startDate": "2023-12-29T11:00:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T11:15:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T11:30:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T11:45:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T12:00:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T12:15:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T12:30:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T12:45:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T13:00:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T13:15:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T13:30:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T13:45:00.000Z",
 *       "duration": 90,
 *       "status": "UNAVAILABLE",
 *       "tableCombinations": [],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T14:00:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T14:15:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T14:30:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T14:45:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     },
 *     {
 *       "startDate": "2023-12-29T15:00:00.000Z",
 *       "duration": 90,
 *       "status": "AVAILABLE",
 *       "tableCombinations": [
 *         {
 *           "tableIds": [
 *             "1ed802ae-708f-4da6-9177-54c3df5d3dd5"
 *           ]
 *         }
 *       ],
 *       "manualApproval": false
 *     }
 *   ]
 * }
 */
```

### getTimeSlots (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { timeSlots } from '@wix/table-reservations';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { timeSlots },
  // Include the auth strategy and host as relevant
});


async function getTimeSlots(reservationLocationId,date,partySize,options) {
  const response = await myWixClient.timeSlots.getTimeSlots(reservationLocationId,date,partySize,options);
};
```

---