Turn a bookable product into a booking: list offerings, check availability, pick a resource, book, and take an online deposit when the product asks for one. Previous: Guide 18 | Next: Guide 20

Reference - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:

Prerequisites

  • A client in lib/lynkow.ts created with a publishableKey (Add Lynkow to an Existing Project).

  • A product whose kind is 'bookable' (Guide 18). Every method below takes its slug or its prod_... id.

  • A terms page chosen in Settings > E-commerce > Store (Terms page): a published page with the Terms of Service category. Every booking is refused until the site has one.

Step 1: List offerings (optional)

An offering is a formula of the product with its own price and duration, for example a 60-minute cut and a 90-minute cut and color.

TypeScript
import { lynkow } from '@/lib/lynkow'

// Each offering (partial): { id, label, priceCents, durationMin }
const offerings = await lynkow.reservations.offerings('haircut')

Prices are integers in cents. The list is empty for a single-price product. When it is not empty, the buyer picks one, and its id goes into the availability query and the booking. The method throws 'NOT_FOUND' when offering selection is not enabled on the site. Pass { locale } as the second argument to read the labels in another language (Guide 6).

Step 2: Check availability

TypeScript
// Each slot (partial): { startsAt, endsAt, available, seatsRemaining }
const { slots, timezone, window } = await lynkow.reservations.availability('haircut', {
  from: '2026-07-10', // YYYY-MM-DD, inclusive
  to: '2026-07-17',
  offeringId: offerings[0]?.id, // omit for a single-price product
})

const open = slots.filter((slot) => slot.available)

startsAt and endsAt are ISO 8601 datetimes, and timezone is the zone to display them in. A range that is too wide is shortened: window.to is the last day actually returned. Slots are not filtered by party size, so compare the party size with seatsRemaining. Availability is never cached.

Step 3: Pick a resource (optional)

When the merchant lets buyers choose a resource, such as a stylist or a room, resources() lists them. Otherwise it returns an empty array and you render no picker.

TypeScript
// Each resource (partial): { id, name }
const resources = await lynkow.reservations.resources('haircut')

Send the chosen id as resourceId on the booking. Omit it to let Lynkow assign a free resource.

Step 4: Create the booking

TypeScript
const booking = await lynkow.reservations.book('haircut', {
  startsAt: open[0].startsAt,     // copied from an available slot
  partySize: 1,
  guestName: 'Alice Martin',
  guestEmail: '[email protected]',
  guestPhone: '+33 6 12 34 56 78', // optional
  offeringId: offerings[0]?.id,    // required when the product has offerings
  resourceId: resources[0]?.id,    // optional
  acceptsTerms: true,              // ticked on this page, by this buyer
})

if (booking.deposit) {
  // `pending` until the deposit is paid: see Online deposit below
} else {
  console.log(`Booking ${booking.reference} is ${booking.status}`) // 'confirmed'
}

A booking without an online deposit is confirmed at once, and the buyer pays on site. The end time and the price are computed by Lynkow, and the booking returns them as endsAt and priceCents.

  • acceptsTerms: true is required. Render an unchecked checkbox that links to the site's terms page, and send true only when the buyer ticked it. The booking records the version of the terms the buyer accepted.

  • An optional locale in the data sets the language of the booking's emails. Without it, the request's or the client's locale applies, then the site's default language.

  • When the client holds a customer session (Guide 20), the booking is attached to that buyer and uses their account email. A site that requires accounts refuses a guest booking.

  • The SDK adds the anti-spam fields. They measure the time since the client was created, so a client created per request must pass { formStartedAt } (when the visitor opened the form, in Unix milliseconds) as the third argument. Pass recaptchaToken there too on a site that uses reCAPTCHA.

bookings.create() takes the same arguments and returns a confirmed booking only. For a product that takes an online deposit, it throws a LynkowError with code 'CONFLICT' after the booking was created as pending. Use book() on any site that takes deposits.

Booking errors

TypeScript
import { isLynkowError } from 'lynkow'

try {
  await lynkow.reservations.book('haircut', data) // data: the object of Step 4
} catch (error) {
  if (!isLynkowError(error)) throw error

  switch (error.apiCode) {
    case 'SLOT_UNAVAILABLE':
    case 'CAPACITY_EXCEEDED':
      // The slot filled after the availability read: read availability again.
      break
    case 'TERMS_NOT_ACCEPTED':
      // Ask the buyer to tick the terms checkbox.
      break
    case 'ACCOUNT_REQUIRED':
      // The site books signed-in buyers only: send the buyer to sign in.
      break
    default:
      throw error
  }
}

apiCode

code

Meaning

TERMS_PAGE_NOT_CONFIGURED

'VALIDATION_ERROR'

The site has no terms page. The buyer cannot fix it.

TERMS_NOT_ACCEPTED

'VALIDATION_ERROR'

acceptsTerms was not true.

SLOT_UNAVAILABLE, CAPACITY_EXCEEDED

'VALIDATION_ERROR'

The slot cannot take this party.

OFFERING_REQUIRED, OFFERING_NOT_FOUND

'VALIDATION_ERROR'

The product has offerings and none, or an unknown one, was sent.

PARTY_SIZE_OUT_OF_RANGE

'VALIDATION_ERROR'

The party size is outside the offering's bounds.

RESOURCE_NOT_IN_POOL

'VALIDATION_ERROR'

The chosen resource cannot be booked for this product.

ACCOUNT_REQUIRED

'FORBIDDEN'

The site requires an account and the client holds no session.

PRODUCT_NOT_FOUND

'NOT_FOUND'

The product is unknown, unpublished or not bookable.

RATE_SUBMISSION_TOO_FAST

'TOO_MANY_REQUESTS'

Sent too soon after the form opened: pass formStartedAt.

RATE_SUBMISSION_EXPIRED

'BAD_REQUEST'

The form was opened too long ago: reload it.

RATE_LIMIT_EXCEEDED

'TOO_MANY_REQUESTS'

Too many bookings from one client in 15 minutes. Booking from your server: forward the buyer's IP (Guide 26).

A 'VALIDATION_ERROR' is HTTP 422. The API reference lists the other codes. Error Handling covers LynkowError in general.

Online deposit

When a product asks for a deposit and the site takes online payments, book() returns the booking as pending with a deposit: amountCents, currency, the payment page's checkoutUrl, a paymentId and a captureToken.

  1. Keep paymentId and captureToken on your server, for example in a short-lived HttpOnly cookie, then send the buyer to checkoutUrl. The captureToken is a secret: never put it in a URL.

  2. After payment, the buyer comes back to /checkout/payment/return?paymentId=... on the site's domain. Card orders use the same return page (Guide 24), so store with the token that this payment is a booking deposit.

  3. On that page, read the payment status:

TypeScript
const { status, bookingStatus } = await lynkow.reservations.refreshPayment(paymentId, captureToken)

if (bookingStatus === 'confirmed') {
  // Paid: show the confirmation and delete the cookie
}

status is the payment's state ('pending', 'processing', 'captured', 'failed' or 'expired', or a reconciliation outcome), and bookingStatus the booking's. The call is safe to repeat. The signed-in buyer who booked can omit captureToken. Without a valid token or session, it throws 'FORBIDDEN' with apiCode 'PAYMENT_CAPABILITY_REQUIRED'.

A buyer who leaves the payment page comes back to /checkout/payment/cancel?bookingId=... instead. book() returns a confirmed booking with no deposit when no online payment is due.

Next Steps