Quickstart

Express

Build a booking API with Express and the Seshn SDK, including webhook signature verification.

Prerequisites

  • Node.js 18+
  • A Seshn account with an API key (sign up)

1. Set up the project

terminal
1mkdir seshn-express && cd seshn-express
2npm init -y
3npm install @seshn/sdk express
4npm install -D typescript @types/express tsx

2. Initialize the Seshn client

src/seshn.ts
1import { Seshn } from '@seshn/sdk';
2
3export const seshn = new Seshn(process.env.SESHN_API_KEY!, {
4 baseUrl: 'https://api.seshn.net',
5});

3. Create the server

Three endpoints cover the core flow: check availability, create and confirm a booking, and receive webhook events.

src/index.ts
1import express from 'express';
2import crypto from 'crypto';
3import { seshn } from './seshn';
4
5const app = express();
6
7// Parse JSON for all routes except webhooks (need raw body there)
8app.use((req, res, next) => {
9 if (req.path === '/webhooks') {
10 express.raw({ type: 'application/json' })(req, res, next);
11 } else {
12 express.json()(req, res, next);
13 }
14});
15
16// ─── GET /availability ──────────────────────────────────────
17app.get('/availability', async (req, res) => {
18 const { serviceId, from, to } = req.query as Record<string, string>;
19
20 const result = await seshn.availability.query({
21 serviceId,
22 from,
23 to,
24 });
25
26 res.json(result.data);
27});
28
29// ─── POST /book ─────────────────────────────────────────────
30app.post('/book', async (req, res) => {
31 const { slotId, contactId, seats } = req.body;
32
33 // Create the booking
34 const { booking } = await seshn.bookings.create({
35 slotId,
36 contactId,
37 seats,
38 });
39
40 // Confirm immediately
41 const { booking: confirmed } = await seshn.bookings.confirm(booking.id);
42
43 res.json(confirmed);
44});
45
46// ─── POST /webhooks ─────────────────────────────────────────
47app.post('/webhooks', (req, res) => {
48 const signature = req.headers['x-webhook-signature'] as string;
49 const event = req.headers['x-webhook-event'] as string;
50 const payload = (req.body as Buffer).toString('utf-8');
51
52 // Verify HMAC signature
53 if (!verifySignature(payload, signature, process.env.SESHN_WEBHOOK_SECRET!)) {
54 res.status(401).json({ error: 'Invalid signature' });
55 return;
56 }
57
58 const data = JSON.parse(payload);
59 console.log(`Received ${event}:`, data);
60
61 // Handle different event types
62 switch (event) {
63 case 'booking.confirmed':
64 // Send confirmation email, sync calendar, etc.
65 break;
66 case 'booking.cancelled':
67 // Process refund, notify staff, etc.
68 break;
69 case 'payment.succeeded':
70 // Update your records
71 break;
72 }
73
74 res.json({ received: true });
75});
76
77// ─── Signature verification ─────────────────────────────────
78function verifySignature(payload: string, header: string, secret: string): boolean {
79 const expected = `sha256=${crypto
80 .createHmac('sha256', secret)
81 .update(payload)
82 .digest('hex')}`;
83
84 return crypto.timingSafeEqual(
85 Buffer.from(header),
86 Buffer.from(expected),
87 );
88}
89
90app.listen(3001, () => {
91 console.log('Server running on http://localhost:3001');
92});

4. Run it

terminal
1SESHN_API_KEY=sk_test_... npx tsx src/index.ts

5. Test the endpoints

terminal
1# Check availability
2curl "http://localhost:3001/availability?serviceId=svc_yoga_class&from=2026-03-20&to=2026-03-27"
3
4# Create a booking
5curl -X POST http://localhost:3001/book \
6 -H "Content-Type: application/json" \
7 -d '{"slotId": "slot_...", "contactId": "ct_jane_doe", "seats": 1}'

Webhook setup

Register your webhook endpoint in the dashboard or via the API. The signing secret is returned once at creation time -- store it securely.

register-webhook.ts
1const webhook = await seshn.webhooks.create({
2 url: 'https://your-domain.com/webhooks',
3 events: ['booking.confirmed', 'booking.cancelled', 'payment.succeeded'],
4});
5
6// Save webhook.secret -- it won't be shown again
7console.log('Webhook secret:', webhook.secret);

What's next

  • API Reference — Explore all endpoints interactively
  • Webhooks — Event types, retries, and delivery logs
  • Bookings — Holds, cancellations, and rescheduling
  • Payments — Charge for bookings with Stripe