# booking (https://docs.salla.dev/twilight/react/sdk/booking)



Use `Salla.booking` for products the merchant sells as a booking, such as a class or an appointment. The customer books first, then picks the date and time on the booking page.

```tsx title="app/components/product/BookButton.tsx"
export function BookButton({ productId }: { productId: number }) {
  return <button onClick={() => window.salla?.booking.add(productId)}>Book now</button>;
}
```

## Methods [#methods]

| Method | Parameters          | Does                                                                         |
| ------ | ------------------- | ---------------------------------------------------------------------------- |
| `add`  | `id, withRedirect?` | Starts a booking for the product. By default it then opens the booking page. |

With `withRedirect` left on (`true`), the SDK goes to the address in the response when it points to the booking page. Pass `false` to stay on the page and handle the response yourself.

```ts
const response = await Salla.booking.add(productId, false);
// response.data.redirect.url is the booking page
```

## Events [#events]

| Event                      | Fires when   | Arguments |
| -------------------------- | ------------ | --------- |
| `booking::added`           | `add` worked | response  |
| `booking::addition.failed` | `add` failed | error     |

## Gotchas [#gotchas]

* `add` without an id rejects at once with "Please provide product id."
* `add` is for booking products. To add any other product, use [`Salla.cart.addItem`](https://docs.salla.dev/twilight/react/sdk/cart).

## See also [#see-also]

* [Cart](https://docs.salla.dev/twilight/react/sdk/cart)
* [Product route](https://docs.salla.dev/twilight/react/routes/product)
