Skip to content
OpticianDayBook home
Features Online booking How it works Pricing FAQ Sign in Book a demo

For web developers

Website booking API

Let patients book from the practice's own website or Shopify shop. Your widget shows live free times and books, moves and cancels appointments straight into the practice's OpticianDayBook diary.

Practices: ask us to switch it on, and we'll send your developer the address to use. If you don't have a developer, our own booking pages do the same job with nothing to build.

  1. What it does
  2. Getting started
  3. Conventions and errors
  4. Endpoints
  5. Paying through Shopify
  6. Bot check
  7. Change and cancel links in emails
  8. Testing checklist

1. What it does

Calls come straight from patients' browsers, so there are no secret keys to protect.

  • It applies the practice's own online booking rules (notice, how far ahead, change cut-off), the same as our own booking pages, and checks every booking against the live diary, so a time can never be booked twice.
  • It never returns patient contact details. Looking up a booking returns the patient's first name only.
  • Services charged online are paid at the shop's Shopify checkout, and the booking is confirmed when Shopify tells us the order is paid.
  • Patients get their confirmation, reminder and change emails from OpticianDayBook, in the practice's branding, with links back to the practice's website.

2. Getting started

Every call goes to the practice's base address, which we send you:

https://opticiandaybook.com/api/public/v1/p/{practice key}

The key in the address is public by design. It only gives access to free times and the practice's own bookings, so it can sit in your theme's JavaScript.

Allowed sites. The API answers only browser requests from the sites the practice has listed. Calls from any other site get 403 origin_not_allowed. Send us every address the widget will run on, as https:// plus the host name only:

  • The shop's own domain, such as https://www.example.com
  • Its .myshopify.com address, such as https://example.myshopify.com, because theme previews run there

IDs. Services and branches are identified by short IDs the practice sets, such as eye-test and high-street. GET /config lists them. If the practice has only one branch, you can leave location out of every call.

3. Conventions and errors

Requests and responses are JSON (Content-Type: application/json). Dates are YYYY-MM-DD and times HH:MM, in the practice's local time (Europe/London). Deadlines such as hold_expires_at are UTC timestamps ending in Z.

Every error has the same shape. The message is written for patients, so you can show it as it is. field names the input at fault, when there is one.

{"error": {"code": "slot_taken", "message": "That time has just been booked. Please pick another."}}
StatusCodeWhen
400invalid_requestA missing or invalid field (see field)
403origin_not_allowedThe call came from a site not on the practice's list
403turnstile_failedThe bot check token was missing or invalid
404not_foundUnknown practice key, or no booking matches the reference and token or email
409slot_takenSomeone else booked that time first
409too_many_holdsThis email already has 2 bookings waiting for payment
409not_changeableThe booking is cancelled or already happened
409too_late_to_changeIt's past the practice's change cut-off
422outside_hoursThat time isn't on the practice's online booking times
429rate_limitedToo many requests: wait before trying again

Rate limits, per visitor IP address: 60 reads (config, slots) a minute; 10 changes (book, look up, move, cancel) a minute; and 10 failed lookups an hour, also counted per email address and per booking reference. The practice may also cap how many online bookings it takes an hour. GET /config can be cached for 5 minutes; nothing else should be.

4. Endpoints

All paths are relative to the base address.

CallWhat it does
GET /configServices, branches, booking rules and the bot check key
GET /slotsTimes for one service, up to 14 days at a time
POST /bookingsMakes a booking
POST /bookings/{reference}/lookupFinds a booking
POST /bookings/{reference}/moveMoves a booking to a new time
POST /bookings/{reference}/cancelCancels a booking

GET /config

Call this first. It lists only the services the practice offers online, each with the branches that can do it.

{
  "practice": {"name": "Smith Opticians", "timezone": "Europe/London", "phone": "01632 960000", "turnstile_site_key": "0x4AAA…"},
  "services": [
    {"id": "eye-test", "name": "Eye test", "duration_minutes": 30, "price_display": "£25",
     "payment": "online", "shopify_variant_id": 44012345678901, "locations": ["high-street"]}
  ],
  "locations": [{"id": "high-street", "name": "High Street", "address": "12 High Street, Exampleton, EX1 2AB"}],
  "rules": {"lead_minutes": 120, "window_days": 60, "change_cutoff_hours": 24, "hold_minutes": 30}
}
  • payment is online when the patient pays at the Shopify checkout, or in_store when they pay at the practice and the booking is confirmed straight away.
  • price_display is for showing only; null means no price is shown.
  • rules are already applied to the times /slots returns. Use them for wording, such as "Changes up to 24 hours before".

GET /slots

GET /slots?service=eye-test&location=high-street&from=2026-12-01&to=2026-12-07

Returns every time in working hours, each marked available true or false, so taken times can be shown greyed out. to can be at most 13 days after from. A day the branch is shut has open: false and no slots.

{"service": "eye-test", "location": "high-street", "days": [
  {"date": "2026-12-01", "open": true, "slots": [{"time": "09:00", "available": true}, {"time": "09:30", "available": false}]},
  {"date": "2026-12-06", "open": false, "slots": []}
]}

POST /bookings

{
  "service": "eye-test",
  "location": "high-street",
  "date": "2026-12-01",
  "time": "09:00",
  "payment": "online",
  "turnstile_token": "…",
  "customer": {
    "first_name": "Sam", "last_name": "Taylor",
    "email": "[email protected]", "phone": "07700 900123",
    "date_of_birth": "1985-04-12",
    "age_confirmed": true,
    "notes": "Wears contact lenses",
    "nhs_eligible": false,
    "reminders": true
  }
}
FieldRequiredNotes
service, date, timeYesFrom /config and /slots
locationWith more than one branch
paymentYesMust match the service's payment in /config
turnstile_tokenWhen the bot check is onSee Bot check
customer.first_name, last_name, email, phoneYesUK numbers, or international with a leading +
customer.age_confirmedYes, trueA tick box the patient must tick. Agree its wording with the practice (for example, that a child is booked by a parent or guardian)
customer.date_of_birthNoHelps the practice match an existing patient
customer.notesNoUp to 1,000 characters, seen by staff only
customer.nhs_eligibleNo"I may be entitled to a free NHS eye test"
customer.remindersNoDefaults to true

Returns 201:

{"reference": "AM-7K3QX9", "status": "held", "service": "eye-test", "location": "high-street",
 "date": "2026-12-01", "time": "09:00", "hold_expires_at": "2026-11-29T15:30:00Z",
 "manage_url": "https://www.example.com/pages/book-an-eye-test?t=…#change"}

status is held for a booking awaiting payment (see Paying through Shopify) or confirmed for one paid at the practice. The patient is emailed when the booking is confirmed.

POST /bookings/{reference}/lookup

Send either the token from the patient's email link, or their email:

{"token": "…64 characters…"}
{"reference": "AM-7K3QX9", "status": "confirmed", "service": "eye-test", "location": "high-street",
 "date": "2026-12-01", "time": "09:00", "customer": {"first_name": "Sam"},
 "paid": true, "can_change": true, "change_deadline": "2026-11-30T09:00:00Z"}

status can be held, confirmed, cancelled, expired (a hold that wasn't paid in time), attended or no_show. A wrong reference, token or email all return the same 404, so the API can't be used to find out who has a booking.

POST /bookings/{reference}/move

The same token or email as the lookup, plus the new time. Returns the booking, as the lookup does. Allowed until change_deadline. Offer new times from /slots, where the booking's current time shows as taken.

{"token": "…", "date": "2026-12-03", "time": "14:30", "location": "high-street"}

POST /bookings/{reference}/cancel

{"token": "…", "reason": "Can't make it"}
{"reference": "AM-7K3QX9", "status": "cancelled", "refund": "full"}

refund is full for a booking paid online (the practice refunds it in Shopify), none for an unpaid hold, or not_applicable for one paid at the practice.

5. Paying through Shopify

A service with payment: "online" is held for 30 minutes while the patient pays at the Shopify checkout, then confirmed when Shopify tells us the order is paid.

  1. POST /bookings with "payment": "online". You get a reference and status: "held".
  2. Add the service's shopify_variant_id to the cart, quantity 1, with the reference as a line item property named exactly Booking reference. Put nothing else about the patient on the order.
  3. Send the patient to checkout, and show them hold_expires_at so they know how long they have.
  4. When the order is paid, Shopify tells us. We confirm the booking and email the patient.

With Shopify's Ajax Cart API, step 2 looks like this:

await fetch('/cart/add.js', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({items: [{
    id: service.shopify_variant_id,
    quantity: 1,
    properties: {'Booking reference': booking.reference}
  }]})
});
window.location.href = '/checkout';
  • What we check. The order must come from the practice's own store, signed with its webhook secret. Only a line with that service's own variant confirms a booking. Any amount is accepted, so discount codes work, and staff can see when less than the list price was paid.
  • If it isn't paid in time. An unpaid hold is released after 30 minutes and becomes expired. A payment that arrives later reinstates the booking if the time is still free; otherwise staff see it as "refund due". Each email address can have at most 2 unpaid holds at once.
  • Cancellations. When a paid booking is cancelled online, it's marked "refund due" and the practice is emailed. Staff refund it in Shopify admin.
  • Webhook setup. In Shopify admin, go to Settings > Notifications > Webhooks > Create webhook. Choose the event Order payment, format JSON, and the webhook address we send you. Then give us the signing secret shown under the webhook list by phone or another secure route, not by email.

6. Bot check

New bookings can be protected by Cloudflare Turnstile, a "not a robot" check that's usually invisible to the patient. Only POST /bookings needs it.

  • GET /config returns practice.turnstile_site_key. If it's null, the check is off. Build for both, as it may be switched on later.
  • If there's a key, render the Turnstile widget with it on the booking form (Cloudflare's guide), and send its token as turnstile_token.
  • Tokens are single-use and expire after 5 minutes. If a booking fails, reset the widget before the patient tries again.
  • We only accept tokens issued on the sites the practice has listed, and we register those sites with Cloudflare first. Until then, every booking fails the check, so send us the list early.

7. Change and cancel links in emails

Our emails send patients back to the practice's own booking page to change or cancel. Send us the page's address, such as https://www.example.com/pages/book-an-eye-test, and links arrive like this:

https://www.example.com/pages/book-an-eye-test?t={64-character token}#change
  1. When the page loads with t in the address, ask the patient for their booking reference. It's in every email we send them.
  2. Call POST /bookings/{reference}/lookup with {"token": t}.
  3. Show the booking, and offer move and cancel if can_change is true, sending the same token.

Patients without the link can give their reference and email address instead: send email in place of token. Until the page is ready, our emails link to our own change page instead.

8. Testing checklist

Work through these on the .myshopify.com preview before going live. Test bookings land in the practice's real diary, so tell the practice when you're testing and cancel each one afterwards.

  • GET /config answers from both the shop's domain and its .myshopify.com address.
  • Taken times and shut days show correctly from /slots.
  • A pay-at-practice service books as confirmed, and the confirmation email arrives.
  • A paid service books as held, goes through checkout, and shows confirmed after payment.
  • An unpaid hold shows expired after 30 minutes.
  • The link in the confirmation email opens your page and finds the booking.
  • Moving and cancelling work, and are refused after the change cut-off.
  • Error messages are shown to the patient as the API words them, including slot_taken.
  • With the bot check on, a booking succeeds, and a retry after a failure gets a fresh token.

Questions, or something not behaving as described here? Email [email protected].

OpticianDayBook home

Practice management and online booking for independent UK opticians.

Part of the BusinessDayBook family
Product
  • Features
  • Online booking
  • Website booking API
  • How it works
  • Pricing
  • Security
  • FAQ
Practices
  • Staff sign in
  • Book a demo
  • Support
Legal
  • Privacy notice
  • Data processing

© 2026 Stable State Consulting Ltd · Company no. 15536612 · Cubo, 12th Floor, Bank House, Pilgrim Street, Newcastle upon Tyne, NE1 6SQ. · ICO registration ZB834299