Skip to main content

Quickstart

Two end-to-end flows that create a bookable resource and a reservation against it. The TypeScript example sets up a restaurant floor plan (which auto-creates the table resources) and books a table through the type-specific tableReservations resource. The Python example uses the unified model — reservation_resources for the bookable type and reservations (with reservation_type) for the booking — then confirms and reads it back.

import { WiilClient } from 'wiil-js';
import {
CanvasUnit,
TableShape,
ResourceType,
PreferredContactMethod,
} from 'wiil-core-js';

async function setupRestaurantReservations() {
const client = new WiilClient({ apiKey: process.env.WIIL_API_KEY! });

// 1. Create a customer
const customer = await client.customers.create({
phone_number: '+15551234567',
firstname: 'John',
lastname: 'Smith',
preferred_language: 'en',
preferred_contact_method: PreferredContactMethod.SMS,
isValidatedNames: false,
});

// 2. Create floor plan with tables (auto-creates the table resources)
const floorPlan = await client.floorPlans.createDefinition({
name: 'Main Dining',
description: 'Primary dining area',
capacity: 10,
canvasDimensions: { width: 800, height: 600, unit: CanvasUnit.PX },
isActive: true,
sections: [
{
name: 'Window Section',
capacity: 10,
color: '#4A90D9',
isActive: true,
sortOrder: 1,
tables: [
{ number: 'W1', x: 100, y: 100, width: 80, height: 80, shape: TableShape.ROUND, minParty: 2, maxParty: 4, combinableWith: [] },
{ number: 'W2', x: 200, y: 100, width: 100, height: 80, shape: TableShape.RECT, minParty: 4, maxParty: 6, combinableWith: [] },
],
},
],
});

// 3. Query available slots for tomorrow
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const localDate = tomorrow.toISOString().split('T')[0];

const slotResponse = await client.tableReservations.getAvailableSlots({
resourceType: ResourceType.TABLE,
localDate: localDate,
partySize: 4,
floorPlanId: floorPlan.id,
maxResults: 10,
});

if (slotResponse.slots.length === 0) {
console.log('No available slots');
return;
}

// 4. Create reservation using first available slot
const slot = slotResponse.slots.find(s => s.isAvailable) || slotResponse.slots[0];

const reservation = await client.tableReservations.create({
resourceId: floorPlan.id,
customerId: customer.id,
floorPlanId: floorPlan.id,
time: slot.startTimeUtcSec, // API expects UTC seconds
duration: 120,
personsNumber: 4,
isVip: true,
notes: 'Anniversary dinner - please prepare special dessert',
});

return { customer, floorPlan, reservation };
}

setupRestaurantReservations().catch(console.error);

Next steps