Skip to guide
AvailKit/ developers

Build your first booking integration.

Start with the short durable booking tutorial. This reference keeps the complete setup, CLI and webhook details.

Install the SDK, create a test key, and save your first booking.

Use https://api.availkit.com for server integrations. Sign in and manage your workspace at app.availkit.com. Start in the test environment so sample bookings stay separate from live work.

Install the SDK and CLI

Use Node 24 or newer. In a new project, install the server-built archive. It contains compiled JavaScript, TypeScript declarations and the CLI, with no runtime package dependencies.

mkdir availkit-example
cd availkit-example
npm init -y
printf 'private/\n' >> .gitignore
npm install https://availkit.dev/downloads/availkit-booking-0.4.0.tgz
npx --no-install availkit --help

Download package · SHA-256 checksum

Create a test API key

  1. Open API keys in your dashboard. Sign in with your email and passkey, then create a workspace if needed.
  2. Select the workspace and test environment. In API keys, select Read and Book for this guide, then review and create the key.
  3. Download the secret while it is shown once. Keep the key file in this example’s private directory. Copy the workspace ID displayed in API keys.

A key belongs to exactly one workspace and environment. The server also limits it to your current account permissions. Keep secrets on your server; never put them in customer code, a URL, source control or command arguments.

Choose only the permissions your integration needs
PermissionUse it for
ReadCatalog, availability, bookings, events and usage reads.
BookCreate, move and cancel bookings. Add Read to find times.
Manage customers and webhooksManage or export contacts and configure webhook subscriptions. Linking a contact to a booking also needs Book.
Edit catalogCreate or change resources, hours, offerings and booking-page settings.
PrivacyPrune expired booking retry receipts. Contact erasure and history pruning also require Manage customers and webhooks.

Once-only secrets cannot be recovered by listing keys. If issuance has an uncertain outcome, stop and inspect the key list; do not automatically issue another key. Revoke keys you no longer need.

On macOS or Linux, protect the downloaded file and configure both the SDK and CLI below. Replace the file name with your actual download and the workspace placeholder with its ID.

mkdir -m 700 private
mv ~/Downloads/YOUR_DOWNLOADED_KEY.key ./private/availkit-test.key
chmod 600 ./private/availkit-test.key
export AVAILKIT_BASE_URL=https://api.availkit.com
export AVAILKIT_WORKSPACE_ID=YOUR_WORKSPACE_ID
export AVAILKIT_CREDENTIAL_FILE="$PWD/private/availkit-test.key"
npx --no-install availkit doctor
npx --no-install availkit auth check
npx --no-install availkit resource list

The CLI accepts one credential source at a time. If you already set AVAILKIT_CREDENTIAL, unset it before using a credential file. Keep private/ out of source control. A read-only integration only needs Read; this first-booking guide additionally needs Book.

Prepare a bookable offering

In the same workspace’s test environment, open Catalog & hours:

  1. Create a resource named “SDK test resource”, timezone UTC, capacity 1.
  2. Configure its weekly hours, for example Monday–Friday, 09:00–17:00. Review and confirm the change.
  3. Create a 30-minute offering named “SDK test visit” using that resource. Copy its offering ID from the catalog.

You can use the SDK or CLI for catalog setup too; those writes need Edit catalog permission. Dashboard setup keeps this example’s integration key limited to Read and Book.

export AVAILKIT_OFFERING_ID=YOUR_TEST_OFFERING_ID

Make your first booking

Save this as first-booking.mjs in your example project. The Node-only factory reads the same private credential file as the CLI, checking its format, owner and permissions. It finds a future time within the next seven days, saves the exact request privately before sending, and sends once. Run it once in your fresh test environment. The installed package also includes this exact file at node_modules/@availkit/booking/examples/first-booking.mjs.

Read the complete first-booking source
// Run once from a new consumer project after following https://availkit.dev/sdk.
// Keep private/ outside source control. A saved intent blocks accidental reruns.
import { createNodeClient } from '@availkit/booking/node';
import { AvailKitError } from '@availkit/booking';
import { openSync, writeFileSync, fsyncSync, closeSync } from 'node:fs';
import { randomUUID } from 'node:crypto';

const workspaceId = process.env.AVAILKIT_WORKSPACE_ID;
const baseUrl = process.env.AVAILKIT_BASE_URL;
const client = await createNodeClient({
  baseUrl, workspaceId,
  credentialFile: process.env.AVAILKIT_CREDENTIAL_FILE,
  credential: process.env.AVAILKIT_CREDENTIAL
});
const from = new Date(Date.now() + 60 * 60 * 1000).toISOString();
const to = new Date(Date.parse(from) + 7 * 86400000).toISOString();
const availability = await client.availability({
  offeringId: process.env.AVAILKIT_OFFERING_ID, from, to
});
if (!availability.slots.length) throw Error('No times: check offering and weekly hours.');
const intent = {
  baseUrl, workspaceId, environment: 'test',
  credentialFingerprint: client.credentialFingerprint,
  createdAt: new Date().toISOString(), key: randomUUID(),
  body: { offeringId: process.env.AVAILKIT_OFFERING_ID,
    start: availability.slots[0].start }
};
const file = openSync('./private/first-booking-intent.json', 'wx', 0o600);
try { writeFileSync(file, JSON.stringify(intent)); fsyncSync(file); }
finally { closeSync(file); }
let booking;
try {
  booking = await client.book(intent.body, intent.key);
} catch (error) {
  console.error(JSON.stringify({
    outcome: error instanceof AvailKitError ? error.outcome : 'unknown',
    action: 'Stop. Keep the intent and original key; inspect current bookings. Do not rerun.'
  }));
  process.exit(1);
}
// The server confirmed this booking even if saving the local result later fails.
console.log('Confirmed booking:', booking.id);
const result = openSync('./private/first-booking-result.json', 'wx', 0o600);
try { writeFileSync(result, JSON.stringify(booking)); fsyncSync(result); }
finally { closeSync(result); }
const current = await client.getBooking(booking.id);
console.log('Current status:', current.status);
node first-booking.mjs
npx --no-install availkit booking list

Look for the same confirmed booking in the dashboard’s Bookings list. Availability is advisory; the server reserves capacity when the booking commits. This example does not link a customer or send customer email.

If a request fails or its response is lost, stop. Keep the saved intent and inspect bookings with the same key and workspace. A timeout can follow a committed booking. Do not delete the intent file and rerun the script. Deliberate replay is limited to the exact saved body and idempotency key, with the original workspace, environment and credential authority, within 24 hours; do not replay after that window.

Create a separate booking with the CLI

Use this as an alternative to the SDK send, or for a deliberately separate booking. First query availability using the offering ID and a future UTC range of at most seven days:

npx --no-install availkit availability OFFERING_ID FROM_UTC TO_UTC

Choose one returned start. Save a private book.json containing {"offeringId":"YOUR_OFFERING_ID","start":"RETURNED_UTC_START"}. Generate one idempotency key with node -e "console.log(crypto.randomUUID())" and retain it with that exact file, workspace, test environment and creation time before sending. Substitute that saved key below:

npx --no-install availkit book ./private/book.json YOUR_SAVED_IDEMPOTENCY_KEY
npx --no-install availkit booking get RETURNED_BOOKING_ID

Each invocation sends once. A new key means a new intent; never generate a replacement key to retry an uncertain booking.

Embed customer booking

Publish a booking page in the dashboard and use its page ID. The guest SDK sends no account cookies or workspace key. It supports explicit guest credentials from another website.

import { PublicBookingClient } from '@availkit/booking/public';
const guest = new PublicBookingClient({
  baseUrl: 'https://api.availkit.com', pageId: 'YOUR_PUBLIC_PAGE_ID'
});
const services = await guest.listOfferings({ limit: 25 });

Before creating a booking, generate separate booking and contact tokens with newGuestToken() and save them with the exact input and idempotency key. A lost response can mean the write committed: never create a fresh intent automatically. Private management links keep booking credentials in the URL fragment, never a query string.

Connect an AI agent

Use the installed CLI with a shell-capable agent. It provides command and input schemas without connecting to the API; no separate server or MCP installation is needed. Give the agent the packaged node_modules/@availkit/booking/AGENTS.md and authorize a specific workspace, environment and task. Configure credentials privately before starting; never paste a key into a prompt.

npx --no-install availkit discover
npx --no-install availkit --json doctor
npx --no-install availkit --json auth check
npx --no-install availkit --json offering list

discover describes exact arguments, JSON inputs, permission bits, pagination, side effects and replay limits. doctor validates local configuration without a network call and gives corrective steps. It cannot verify server permissions or the key’s environment: select test or live deliberately when issuing the key, then use auth check for a read-only authentication check.

Use --json first for versioned result envelopes. A successful command reports confirmed_success; failures distinguish not_sent, rejected and unknown and exit with status 1. On unknown, stop mutations and keep the exact saved intent and original authority. A read can show current state but cannot reconstruct a lost acknowledgment. Never automatically resend or replace an uncertain request.

For a first booking, grant Read and Book. Catalog setup additionally needs Edit catalog; grant it only for an explicitly authorized setup task. Human passkey ceremonies, key issuance and account recovery are outside the agent CLI.

Receive signed webhooks

Create a subscription in the dashboard and save its signing secret when it is shown once. Deliveries send AvailKit-Delivery-Id and AvailKit-Signature: t=SECONDS,v1=HEX. There is no separate event-ID header; the signed body contains the event.

Before parsing JSON, verify HMAC-SHA256 over the timestamp, a literal period, and the exact raw request bytes. Decode the signing secret as base64url into 32 bytes, compare the hexadecimal tag in constant time, and reject duplicate signing headers or timestamps more than 300 seconds from your clock. Keep the raw body bounded to 16 KiB.

This illustrative payload shows the current wire format:

{
  "schemaVersion": 1,
  "deliveryId": "11111111111111111111111111111111",
  "subscriptionId": "22222222222222222222222222222222",
  "workspaceId": "33333333333333333333333333333333",
  "environment": "test",
  "event": {
    "id": "44444444444444444444444444444444",
    "sequence": 1,
    "type": "booking.created",
    "bookingId": "55555555555555555555555555555555",
    "occurredAt": "2026-10-22T12:00:00Z"
  }
}

Check that the signed delivery ID matches the header and that the subscription, workspace and environment match your configuration. Store the delivery ID with your business effect in one durable transaction, then acknowledge with a 2xx response. A repeated delivery must return success without applying the effect again.

Delivery is at least once, with at most five attempts. HTTP 408, 425, 429 and 5xx responses, or an uncertain transport outcome, can retry after 5 seconds, 30 seconds, 2 minutes and 10 minutes. Most other 4xx responses are terminal. Disabling a subscription prevents new attempts; an already admitted request may have reached you.

Operate reliably

Webhooks use signed, at-least-once delivery. Verify signatures against the exact request bytes and deduplicate by delivery ID. Keep booking links and integration keys private. Add and test a spare passkey in dashboard Account & security, and save recovery codes offline. Recovery replaces account access and revokes old sessions and keys; it requires the account email address as its identifier and an unused saved code as authority. Ordinary sign-in and continuation without a session after a lost finish acknowledgment additionally require mailbox proof and the working replacement passkey. Read the access and recovery limits.

Browse endpoints and schemas. The explorer uses an explicitly supplied bearer key and omits cookies; account and guest flows remain reference-only there.