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.
- TypeScript
- Python
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);
from time import time
from wiil import WiilClient
from wiil.models.business_mgt import CreateReservation, CreateResource
from wiil.types import PaginationRequest
client = WiilClient(api_key="your-api-key")
now_ms = int(time() * 1000)
# 1. Create a bookable resource
table = client.reservation_resources.create(
CreateResource(
resource_type="table",
name="Table 5",
description="Window-side table for 4 guests",
capacity=4,
is_available=True,
location="Main dining area",
amenities=["Window view", "Booth seating"],
reservation_duration=2,
reservation_duration_unit="hours",
sync_enabled=False,
)
)
# 2. Book it through the unified reservations resource
reservation = client.reservations.create(
CreateReservation(
reservation_type="table",
resource_id=table.id,
customer_id="cust_123",
start_time=now_ms + 3600000,
end_time=now_ms + 7200000,
duration=2,
persons_number=4,
total_price=0,
deposit_paid=0,
notes="Window table preferred",
is_resource_reservation=True,
)
)
# 3. Confirm it
confirmed = client.reservations.update_status(reservation.id, "confirmed")
# 4. Read it back
loaded = client.reservations.get(reservation.id)
customer_reservations = client.reservations.get_by_customer(
"cust_123", PaginationRequest(page=1, page_size=20)
)
print("Resource:", table.id)
print("Reservation:", reservation.id, "->", confirmed.status)
print("Customer reservations:", customer_reservations.meta.total_count)
Next steps
- Resources & instances — bookable types and physical units
- Floor plans — dining layouts that create table resources
- Table reservations — floor plans and dining bookings
- Room reservations — lodging stays
- Rental reservations — equipment and vehicles
- Settings & operations — per-location rules