Home /Tutorials/Booking an appointment
Booking an appointment

NoteTo book an appointment for a client, you’ll need the client’s uid, which can be found by following the Finding user information tutorial. Additionally, the k_business value you received in your API/SDK welcome email will also be required for this tutorial.

Start by choosing the location where you want the appointment to take place. You’ll use the k_location value in the next steps.

// Retrieve the list of locations for a business.
$o_model = new \WellnessLiving\Wl\Location\ListModel($o_config);
$o_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_model->k_business='3';

// Perform the request.
$o_model->get();

// Print the location ID, name, and address.
foreach($o_model->a_location as $a_location)
 echo $a_location['k_location'].'    '.$a_location['s_title'].'    '.$a_location['text_address']."\n";

Each appointment will belong to a category. A list of the categories can be retrieved by using the CategoryModel endpoint below. Once the list of categories is retrieved, record the k_service_category value for the client’s selection.

// Retrieve appointment categories.
$o_category_model = new \WellnessLiving\Wl\Appointment\Book\Service\CategoryModel($o_config);
$o_category_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_category_model->is_backend=true;
$o_category_model->is_tab_all=true;
$o_category_model->k_location='3';
$o_category_model->uid='4';

// Perform the request.
$o_category_model->get();

// Print the appointment category key and name.
foreach($o_category_model->a_category as $a_category)
{
 echo $a_category['k_service_category'].'    '.$a_category['s_title']."\n";
}

You can also retrieve a list of available appointments for each category. Record the k_service value, which identifies the general type of appointment for the user’s choice.

// Retrieve a list of appointments in a category.
$o_servicelist_model = new \WellnessLiving\Wl\Appointment\Book\Service\ServiceListModel($o_config);
$o_servicelist_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_servicelist_model->is_backend=true;
$o_servicelist_model->is_tab_all=true;
$o_servicelist_model->k_location='3';
$o_servicelist_model->k_service_category='2';
$o_servicelist_model->uid='4';

// Perform the request.
$o_servicelist_model->get();

// Print the appointment key and name.
foreach($o_servicelist_model->a_service as $a_service)
 echo $a_service['k_service'].'    '.$a_service['s_service']."\n";

Next, you’ll need to retrieve a list of days that are available for the client to book and select a day for the appointment.

// Retrieve available days for the appointment booking.
$o_calendar_model = new \WellnessLiving\Wl\Appointment\Book\Schedule\CalendarModel($o_config);
$o_calendar_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_calendar_model->dt_date='2023-03-24 00:00:00'; // Dates will be returned including and after this time.
$o_calendar_model->i_duration='60';
$o_calendar_model->id_gender_staff=1;
$o_calendar_model->is_unavailable=1;
$o_calendar_model->k_location='3';
$o_calendar_model->k_service='2';
$o_calendar_model->uid='4';

// Perform the request.
$o_calendar_model->get();

// Print the available days.
foreach($o_calendar_model->a_date as $a_date)
{
 echo $a_date['dt_date']."\n";
}

After selecting a day, you can then check what times are available for the appointment. Once you’ve selected the day and time, you’ll have enough information to check for the client’s applicable Purchase Options.

// Retrieve available time in the selected day.
$o_daytime_model = new \WellnessLiving\Wl\Appointment\Book\Schedule\DayTimeModel($o_config);
$o_daytime_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_daytime_model->dt_date='2023-03-27 00:00:00';
$o_daytime_model->i_duration='60';
$o_daytime_model->id_gender_staff=1;
$o_daytime_model->is_unavailable=0;
$o_daytime_model->k_location='3';
$o_daytime_model->k_service='2';
$o_daytime_model->uid='4';
$o_daytime_model->get();

// Print available times.
foreach($o_daytime_model->a_time as $a_time)
{
  echo $a_time['dt_date']."\n";
}

You can check for an applicable Purchase Option as well as whether the client owns one. Purchase Options the client owns will be returned in a_login_promotion, while the ones available for purchase will be returned in the a_purchase property. If the client needs to buy a Purchase Option to book this appointment, they can do so using a separate set of calls outlined in the Making a purchase for a client tutorial or as part of the booking process using a similar format outlined in the Booking a class tutorial.

// Retrieve applicable appointment Purchase Options.
$o_purchase_model = new \WellnessLiving\Wl\Appointment\Book\Purchase\PurchaseModel($o_config);
$o_purchase_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_purchase_model->dt_date='2023-03-27 14:30:00';
$o_purchase_model->i_duration=60;
$o_purchase_model->is_backend=1;
$o_purchase_model->k_location='3';
$o_purchase_model->k_service='2';
$o_purchase_model->uid='4';

// Perform the request.
$o_purchase_model->get();

// Print the existing Purchase Option's information.
foreach($o_purchase_model->a_login_promotion as $a_login_promotion)
{
 echo $a_login_promotion['id_program'].' '.$a_login_promotion['k_login_promotion'].' '.$a_login_promotion['s_title']."\n";
}

// Print the available Purchase Option`s name, id_purchase_item::k_id, and price.
foreach($o_purchase_model->a_purchase as $a_purchase)
{
 echo $a_purchase['s_title'].'    '.$a_purchase['id_purchase_item'].'::'.$a_purchase['k_id'].'    '.$a_purchase['f_price']."\n";
}

With all the preceding information set, you can now book the actual appointment. This example shows the call needed for a client who already has a suitable Purchase Option. If successful, the endpoint will return one or more entries in a_appointment. The values k_appointment and s_code in the result can also be used to edit the appointment later.

// Schedule an appointment.
$o_finish_model = new \WellnessLiving\Wl\Appointment\Book\Finish\Finish47Model($o_config);
$o_finish_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session.
$o_finish_model->is_backend=1;
$o_finish_model->k_business='3';
$o_finish_model->k_location='3';

$o_finish_model->uid='4';
$o_finish_model->a_book_data=[
 'dt_date' => '2023-04-04 14:30:00',
 'i_duration' => 60,
 'is_backend' => 1,
 'is_staff_confirm' => 0,
 'id_class_tab' => \WellnessLiving\Wl\Classes\Tab\TabSid::SERVICE, // Specifies this is an appointment.
 'k_service' => '2',
 'uid' => '4'
];

// Perform the request.
$o_finish_model->post();

// Print the keys of the booked appointment(s).
foreach($o_finish_model->a_appointment as $a_appointment)
{
 echo $a_appointment['k_appointment']."\n";
}