Skip to main content

Quickstart

import { WiilClient } from 'wiil-js';
import { AppointmentStatus, PreferredContactMethod } from 'wiil-core-js';

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

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

// 2. Create a service category
const category = await client.serviceCategories.create({
organizationId: 'org_salon',
name: 'Hair Services',
description: 'All hair-related services',
displayOrder: 1,
isActive: true,
});

// 3. Create a service
const haircut = await client.businessServices.create({
organizationId: 'org_salon',
name: 'Haircut & Style',
description: 'Professional haircut with styling',
duration: 60,
bufferBefore: 0,
bufferAfter: 0,
basePrice: 50.00,
isBookable: true,
isActive: true,
requiredResources: [],
lateCancelFeePercent: 50,
noShowFeePercent: 100,
});

// 4. Create a service provider (stylist)
const stylist = await client.servicePersons.create({
name: 'Sarah Johnson',
description: 'Senior stylist',
isActive: true,
bookableOnline: true,
bookableByStaff: true,
});

// 5. Link the service to the provider
await client.serviceProviders.create({
serviceId: haircut.id,
providerId: stylist.id,
active: true,
});

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

const slotResponse = await client.serviceAppointments.getAvailableSlots({
serviceId: haircut.id,
localDate: localDate,
providerId: stylist.id,
maxResults: 10,
});

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

// 7. Book the first available slot
const slot = slotResponse.slots[0];
// API expects UTC seconds
const duration = Math.round((slot.endTimeUtcSec - slot.startTimeUtcSec) / 60);

const appointment = await client.serviceAppointments.create({
businessServiceId: haircut.id,
customerId: customer.id,
startTime: slot.startTimeUtcSec,
endTime: slot.endTimeUtcSec,
duration: duration,
totalPrice: 50.00,
depositPaid: 0,
});

// 8. Confirm the appointment
const confirmed = await client.serviceAppointments.updateStatus(
appointment.id,
AppointmentStatus.CONFIRMED
);

console.log(`Appointment Status: ${confirmed.status}`);
return { customer, category, service: haircut, stylist, appointment: confirmed };
}

setupSalonBooking().catch(console.error);

Next steps