Bookings Quick Start

The SDK bookings module allows you to take advantage of Wix Bookings business services in a site or app you build on any platform. This means you can allow your clients to book and pay for services online. This tutorial shows you how to use the bookings module to create a flow where a visitor can select a service from your Wix Bookings service list, pick an available time slot, and check out.

The tutorial is based on the Wix Headless example site. You can test out the live example site, or fork the site's code repo to use as a starting point for your own site or app.

This implementation focuses on simplicity and understandability, rather than feature richness, performance, or completeness. For details about additional functionality, see Wix Bookings in the API Reference.

Looking for a more comprehensive example site integrating Wix Headless APIs for bookings management? Check out our starter templates.

Note: The code in this tutorial is written in JSX, but you can use the SDK in any JavaScript environment.

Implementing the booking flow includes the following steps:

  1. Set up the Wix Headless environment.
  2. Import the SDK modules and create an SDK client.
  3. Create your services.
  4. Fetch your services and available slots.
  5. Implement checkout.
  6. Display the UI.

Step 1: Set up the Wix Headless environment

Before using the SDK, there are a few things you need to set up on your Wix account and in your external site or app's coding environment.

To set up the Wix Headless environment, follow these steps:

  1. If you haven't already, create a project.
    When prompted to add functionalities to your new project, select Bookings.

  2. Set up authorization for your site by creating and configuring an OAuth app.

  3. Set a domain to be used by Wix-managed pages.

  4. Set a domain that Wix can redirect to after completing a Wix-managed process.

  5. Install the API client and relevant SDK module packages by running the following commands:
    For NPM:

    Copy

    For Yarn:

    Copy
  6. Install the react package to handle UI rendering and the js-cookie package to handle session cookies. Run the following commands:
    For NPM:

    Copy

    For Yarn:

    Copy

Step 2: Import the SDK modules and create an SDK client

The next step is to set up your code file to run the SDK functions. To set up the code file, follow these steps:

  1. Add the following import statements to the top of your code file:
    Copy
  2. Create an SDK client by adding the following code to your code file. Replace the value for clientId with your OAuth app's client ID. You can find the ID in your project's Headless Settings menu.
    The value for tokens is the 'session' cookie on the site visitor's browser. It's used to make calls to the Wix API. This way, you can maintain previous visitor sessions. For information about managing session cookies, see Session Token Management.
    Copy

Step 3: Create your services

Create the services your visitors will book. It's important to also define your bookings forms.

Step 4: Fetch your services and available slots

Define functions to fetch your Wix Bookings services and availability. These functions use the queryServices() function to find the services and the queryAvailability() function to find the available slots for a given service and date.

  1. Fetch your Wix Bookings services.
    Use the useEffect hook to make sure this code runs after the component is rendered. This ensure that your bookings data is available when the component mounts.
Copy
  1. Fetch the service's related slots:
Copy

Note: Start and end dates are ISO formatted objects.

Step 5: Implement checkout

Once a slot is selected, the visitor can initiate Wix’s secure checkout and complete the booking process.

Define a function called createRedirect() that's called when the checkout button in your UI is clicked. The function uses the createRedirectSession() to create a checkout URL for a given bookings slot. The visitor is then redirected to the checkout URL to complete the checkout. A visitor can choose to log in to your site or app during the Wix checkout process.

Note: When redirecting from Wix to an external site, Wix validates that the provided URL is registered under an allowed domain for the given client ID. Therefore, you must add your domain to the OAuth app.

Copy

Step 6: Display the UI

Create a dynamic services list page and connect the elements on your site or app to the relevant fields from your Wix Bookings services.

Use each services's slug or service ID as an identifier and present more information related to each service, such as its name.

  1. The example below uses ID for simplicity, but it's common practice to create friendly urls, using the service.mainSlug.name value instead of service ID:
Copy
  1. Display the slots on a calendar, given a date range, for the selected service:
Copy

Complete code example

You can use the following full code example as a starting point for developing your own site:

Copy
Did this help?