Skip to Content
Developers

Bookings in your calendar

Copy every booking into Google Calendar or Outlook, update it when it moves and remove it when it is cancelled.

For a shop that plans in a shared Google or Outlook calendar, or an owner who wants every chair's day next to their own appointments.

WeerOm tells your server about each booking that is made, changed or cancelled, through webhooks. Your code writes each one to the calendar as an event, keyed by the booking's id, so a move updates the event instead of adding a second one. A cancelled booking removes its event. A job that asks every 5 minutes does the same where nobody can add a webhook address.

WhatYou need
KeyRead key A read key, on a server.
WebhookAn address for Booking made, Booking changed and Booking cancelled, which the shop adds in its admin. See Webhooks.
EndpointsGET /bookings for the first fill and for polling, GET /staff for names.
CalendarYour own code that writes to Google Calendar or Outlook.

One staff member's own agenda

A staff member who only wants their own bookings on their phone needs no code. The admin has a calendar feed for each staff member under Team, Barbers, which any calendar app can subscribe to. Use the API when you want your own titles, one shared calendar, or a calendar you write to yourself.

Steps

  1. On the first run, read every booking from now on: GET /bookings?starts_after=<now>&order=asc.
  2. Write each one to the calendar. Store the calendar's event id next to the booking id, or put the booking id in the event, so you can find the event again.
  3. From then on, act on each webhook: update the event for booking.created and booking.updated, remove it for booking.cancelled.
  4. Without webhooks, remember the highest updated_at you saw across all pages. Every 5 minutes, read GET /bookings?updated_after=<that value>, update each event, and remove the event of each booking with status: "cancelled".

What a booking holds

{
  "object": "booking",
  "id": "0b6f2a4e-5d1c-4f7a-9a3e-2c8d1e6f4b90",
  "code": "UEAMEFC9",
  "status": "confirmed",
  "starts_at": "2026-11-21T09:30:00.000Z",
  "ends_at": "2026-11-21T10:15:00.000Z",
  "minutes": 45,
  "staff_id": "8e1d5b7c-3a9f-4d20-b6c4-7a2e0f9d1c53",
  "service": { "id": "c2a41f6e-8d3b-4e97-b5a0-1f7c9e2d4a68", "name": "Knippen en baard" },
  "customer": { "id": "5f0c9d3a-7b2e-4c61-8a4d-9e1f3b6c2d75", "name": "Lotte Peeters", "email": "[email protected]", "phone": "+32470123456" },
  "comments": "",
  "updated_at": "2026-11-18T14:02:11.000Z"
}

starts_at and ends_at are UTC, with the Z that says so. Pass them with that zone, or convert them to the shop's time_zone from GET /shop, whichever your calendar's API asks for.

With webhooks

upsertCalendarEvent(booking, staffName) and removeCalendarEvent(bookingId) stand for your own code. Fill them in from the Google Calendar or Microsoft Graph documentation. This page does not describe either API.

Messages can arrive out of order: a retry of an older move can land after a newer one. Keep the updated_at you last wrote for each booking, and skip a message that is older.

calendar-webhook.js
// Node 22. verify() is the function from the Webhooks guide.
import { createServer } from "node:http";
import { verify } from "./verify.js";

const SECRET = process.env.WEEROM_WEBHOOK_SECRET;
const EVENTS = ["booking.created", "booking.updated", "booking.cancelled"];

createServer((req, res) => {
  const chunks = [];
  req.on("data", (chunk) => chunks.push(chunk));
  req.on("end", async () => {
    const raw = Buffer.concat(chunks);
    if (!verify(raw, req.headers["weerom-signature"], SECRET)) {
      res.writeHead(400).end();
      return;
    }
    const message = JSON.parse(raw.toString("utf8"));
    if (EVENTS.includes(message.type)) {
      await queueBooking(message.data.object);
    }
    res.writeHead(200).end();
  });
}).listen(3000);

// The worker, run from your own queue.
export async function applyBooking(booking, staffName) {
  const written = await lastWrittenAt(booking.id);
  if (written && written >= booking.updated_at) return; // older or the same

  if (booking.status === "cancelled") {
    await removeCalendarEvent(booking.id);
  } else {
    await upsertCalendarEvent(booking, staffName.get(booking.staff_id));
  }
  await rememberWrittenAt(booking.id, booking.updated_at);
}

The updated_at check also makes a message that arrives twice harmless. Read GET /staff once an hour for staffName: staff changes send no webhook.

The polling job

sync-calendar.js
import { readFile, writeFile } from "node:fs/promises";

const BASE = "https://api.weerom.com/v1";
const STATE_FILE = "./calendar-state.json";

async function weerom(path) {
  const response = await fetch(`${BASE}${path}`, {
    headers: { Authorization: `Bearer ${process.env.WEEROM_KEY}` },
  });
  const json = await response.json();
  if (!response.ok) {
    throw new Error(`${response.status} ${json.error.code}: ${json.error.message}`);
  }
  return json;
}

async function loadState() {
  try {
    return JSON.parse(await readFile(STATE_FILE, "utf8"));
  } catch {
    return { lastUpdatedAt: null };
  }
}

export async function syncCalendar() {
  const state = await loadState();
  const staff = await weerom("/staff");
  const staffName = new Map(staff.data.map((person) => [person.id, person.name]));

  let highest = state.lastUpdatedAt;
  let cursor = null;
  do {
    const query = new URLSearchParams({ limit: "100", order: "asc" });
    if (state.lastUpdatedAt) {
      // A minute of overlap. An event written twice is the same event.
      const since = new Date(Date.parse(state.lastUpdatedAt) - 60_000);
      query.set("updated_after", since.toISOString());
    } else {
      query.set("starts_after", new Date().toISOString());
    }
    if (cursor) query.set("cursor", cursor);
    const page = await weerom(`/bookings?${query}`);

    for (const booking of page.data) {
      if (booking.status === "cancelled") {
        await removeCalendarEvent(booking.id);
      } else {
        await upsertCalendarEvent(booking, staffName.get(booking.staff_id));
      }
      if (!highest || booking.updated_at > highest) highest = booking.updated_at;
    }
    cursor = page.has_more ? page.next_cursor : null;
  } while (cursor);

  await writeFile(STATE_FILE, JSON.stringify({ lastUpdatedAt: highest }));
}

await syncCalendar();

Two details:

  • The list stays sorted by starts_at even with updated_after, so the job takes the highest updated_at from every page, not from the last one.
  • updated_after leaves out a booking changed at exactly that moment. The minute of overlap catches it, and the upsert by id makes a second write harmless.

How often

With webhooks, an event moves a few seconds after the booking does. Run the polling job once a night as well, to catch a message your server lost while it was down for more than 33 hours.

Without webhooks, every 5 minutes. A quiet run is 2 requests, one for the staff and one for the bookings. That is 24 requests an hour, against 120 a minute for the key. A shop's day rarely changes faster than that. Run it every minute if the shop wants it sooner, at 2 requests a minute.

Limits

  • One way. An event moved in Google Calendar or Outlook stays where WeerOm had it on the next change. A write key could move the booking with POST /bookings/{id}/reschedule, but deciding which side wins is yours to build.
  • No breaks. Time staff blocked off is not a booking, and the API leaves it out.
  • Customer details in a calendar. Every event holds a customer's name and phone if you put them there. Share that calendar only with people who may see them.

On this page