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.
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.comaddress, such ashttps://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."}}
| Status | Code | When |
|---|---|---|
| 400 | invalid_request | A missing or invalid field (see field) |
| 403 | origin_not_allowed | The call came from a site not on the practice's list |
| 403 | turnstile_failed | The bot check token was missing or invalid |
| 404 | not_found | Unknown practice key, or no booking matches the reference and token or email |
| 409 | slot_taken | Someone else booked that time first |
| 409 | too_many_holds | This email already has 2 bookings waiting for payment |
| 409 | not_changeable | The booking is cancelled or already happened |
| 409 | too_late_to_change | It's past the practice's change cut-off |
| 422 | outside_hours | That time isn't on the practice's online booking times |
| 429 | rate_limited | Too 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.
| Call | What it does |
|---|---|
GET /config | Services, branches, booking rules and the bot check key |
GET /slots | Times for one service, up to 14 days at a time |
POST /bookings | Makes a booking |
POST /bookings/{reference}/lookup | Finds a booking |
POST /bookings/{reference}/move | Moves a booking to a new time |
POST /bookings/{reference}/cancel | Cancels 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}
}
paymentisonlinewhen the patient pays at the Shopify checkout, orin_storewhen they pay at the practice and the booking is confirmed straight away.price_displayis for showing only;nullmeans no price is shown.rulesare already applied to the times/slotsreturns. 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
}
}
| Field | Required | Notes |
|---|---|---|
service, date, time | Yes | From /config and /slots |
location | With more than one branch | |
payment | Yes | Must match the service's payment in /config |
turnstile_token | When the bot check is on | See Bot check |
customer.first_name, last_name, email, phone | Yes | UK numbers, or international with a leading + |
customer.age_confirmed | Yes, true | A 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_birth | No | Helps the practice match an existing patient |
customer.notes | No | Up to 1,000 characters, seen by staff only |
customer.nhs_eligible | No | "I may be entitled to a free NHS eye test" |
customer.reminders | No | Defaults 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.
POST /bookingswith"payment": "online". You get areferenceandstatus: "held".- Add the service's
shopify_variant_idto the cart, quantity 1, with the reference as a line item property named exactlyBooking reference. Put nothing else about the patient on the order. - Send the patient to checkout, and show them
hold_expires_atso they know how long they have. - 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 /configreturnspractice.turnstile_site_key. If it'snull, 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
- When the page loads with
tin the address, ask the patient for their booking reference. It's in every email we send them. - Call
POST /bookings/{reference}/lookupwith{"token": t}. - Show the booking, and offer move and cancel if
can_changeistrue, sending the sametoken.
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 /configanswers from both the shop's domain and its.myshopify.comaddress.- 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 showsconfirmedafter payment. - An unpaid hold shows
expiredafter 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].