{"id":74,"date":"2022-08-01T06:45:21","date_gmt":"2022-08-01T06:45:21","guid":{"rendered":"https:\/\/www.wellnessliving.com\/developer-portal\/?p=74"},"modified":"2024-11-11T03:27:54","modified_gmt":"2024-11-11T03:27:54","slug":"booking-an-appointment","status":"publish","type":"post","link":"https:\/\/www.wellnessliving.com\/developer-portal\/tutorials\/booking-an-appointment\/booking-an-appointment\/","title":{"rendered":"Booking an appointment"},"content":{"rendered":"\n<p><div class=\"note\"><strong>Note<\/strong>To book an appointment for a client, you\u2019ll need the client\u2019s <span class=\"coding_type\">uid<\/span>, which can be found by following the <a href=\"#_Finding_user_information\">Finding user information<\/a> tutorial. Additionally, the <span class=\"coding_type\">k_business<\/span> value you received in your API\/SDK welcome email will also be required for this tutorial.<\/div><\/p>\n\n\n\n<p>Start by choosing the location where you want the appointment to take place. You\u2019ll use the <span class=\"coding_type\">k_location<\/span> value in the next steps.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve the list of locations for a business.\n$o_model = new \\WellnessLiving\\Wl\\Location\\ListModel($o_config);\n$o_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_model->k_business='3';\n\n\/\/ Perform the request.\n$o_model->get();\n\n\/\/ Print the location ID, name, and address.\nforeach($o_model->a_location as $a_location)\n echo $a_location['k_location'].'    '.$a_location['s_title'].'    '.$a_location['text_address'].\"\\n\";<\/pre>\n\n\n\n<p>Each appointment will belong to a category. A list of the categories can be retrieved by using the <a href=\"https:\/\/github.com\/wellnessliving\/wl-sdk\/blob\/627b20c6c25ea95a4b061921ac9aa51ac2e8f46c\/WellnessLiving\/Wl\/Appointment\/Book\/Service\/CategoryModel.php\">CategoryModel<\/a> endpoint below. Once the list of categories is retrieved, record the <span class=\"coding_type\">k_service_category<\/span> value for the client\u2019s selection.<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve appointment categories.\n$o_category_model = new \\WellnessLiving\\Wl\\Appointment\\Book\\Service\\CategoryModel($o_config);\n$o_category_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_category_model->is_backend=true;\n$o_category_model->is_tab_all=true;\n$o_category_model->k_location='3';\n$o_category_model->uid='4';\n\n\/\/ Perform the request.\n$o_category_model->get();\n\n\/\/ Print the appointment category key and name.\nforeach($o_category_model->a_category as $a_category)\n{\n echo $a_category['k_service_category'].'    '.$a_category['s_title'].\"\\n\";\n}<\/pre>\n\n\n\n<p>You can also retrieve a list of available appointments for each category. Record the <span class=\"coding_type\">k_service<\/span> value, which identifies the general type of appointment for the user\u2019s choice.<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve a list of appointments in a category.\n$o_servicelist_model = new \\WellnessLiving\\Wl\\Appointment\\Book\\Service\\ServiceListModel($o_config);\n$o_servicelist_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_servicelist_model->is_backend=true;\n$o_servicelist_model->is_tab_all=true;\n$o_servicelist_model->k_location='3';\n$o_servicelist_model->k_service_category='2';\n$o_servicelist_model->uid='4';\n\n\/\/ Perform the request.\n$o_servicelist_model->get();\n\n\/\/ Print the appointment key and name.\nforeach($o_servicelist_model->a_service as $a_service)\n echo $a_service['k_service'].'    '.$a_service['s_service'].\"\\n\";<\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>Next, you\u2019ll need to retrieve a list of days that are available for the client to book and select a day for the appointment.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve available days for the appointment booking.\n$o_calendar_model = new \\WellnessLiving\\Wl\\Appointment\\Book\\Schedule\\CalendarModel($o_config);\n$o_calendar_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_calendar_model->dt_date='2023-03-24 00:00:00'; \/\/ Dates will be returned including and after this time.\n$o_calendar_model->i_duration='60';\n$o_calendar_model->id_gender_staff=1;\n$o_calendar_model->is_unavailable=1;\n$o_calendar_model->k_location='3';\n$o_calendar_model->k_service='2';\n$o_calendar_model->uid='4';\n\n\/\/ Perform the request.\n$o_calendar_model->get();\n\n\/\/ Print the available days.\nforeach($o_calendar_model->a_date as $a_date)\n{\n echo $a_date['dt_date'].\"\\n\";\n}<\/pre>\n\n\n\n<p>After selecting a day, you can then check what times are available for the appointment. Once you\u2019ve selected the day and time, you\u2019ll have enough information to check for the client\u2019s applicable Purchase Options.<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve available time in the selected day.\n$o_daytime_model = new \\WellnessLiving\\Wl\\Appointment\\Book\\Schedule\\DayTimeModel($o_config);\n$o_daytime_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_daytime_model->dt_date='2023-03-27 00:00:00';\n$o_daytime_model->i_duration='60';\n$o_daytime_model->id_gender_staff=1;\n$o_daytime_model->is_unavailable=0;\n$o_daytime_model->k_location='3';\n$o_daytime_model->k_service='2';\n$o_daytime_model->uid='4';\n$o_daytime_model->get();\n\n\/\/ Print available times.\nforeach($o_daytime_model->a_time as $a_time)\n{\n  echo $a_time['dt_date'].\"\\n\";\n}<\/pre>\n\n\n\n<p>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 <span class=\"coding_type\">a_login_promotion<\/span>, while the ones available for purchase will be returned in the <span class=\"coding_type\">a_purchase<\/span> 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 <a href=\"#_Making_a_purchase\">Making a purchase for a client<\/a> tutorial or as part of the booking process using a similar format outlined in the <a href=\"#_Booking_a_class\">Booking a class<\/a> tutorial.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve applicable appointment Purchase Options.\n$o_purchase_model = new \\WellnessLiving\\Wl\\Appointment\\Book\\Purchase\\PurchaseModel($o_config);\n$o_purchase_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_purchase_model->dt_date='2023-03-27 14:30:00';\n$o_purchase_model->i_duration=60;\n$o_purchase_model->is_backend=1;\n$o_purchase_model->k_location='3';\n$o_purchase_model->k_service='2';\n$o_purchase_model->uid='4';\n\n\/\/ Perform the request.\n$o_purchase_model->get();\n\n\/\/ Print the existing Purchase Option's information.\nforeach($o_purchase_model->a_login_promotion as $a_login_promotion)\n{\n echo $a_login_promotion['id_program'].' '.$a_login_promotion['k_login_promotion'].' '.$a_login_promotion['s_title'].\"\\n\";\n}\n\n\/\/ Print the available Purchase Option`s name, id_purchase_item::k_id, and price.\nforeach($o_purchase_model->a_purchase as $a_purchase)\n{\n echo $a_purchase['s_title'].'    '.$a_purchase['id_purchase_item'].'::'.$a_purchase['k_id'].'    '.$a_purchase['f_price'].\"\\n\";\n}<\/pre>\n\n\n\n<p>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 <span class=\"coding_type\">a_appointment<\/span>. The values <span class=\"coding_type\">k_appointment<\/span> and <span class=\"coding_type\">s_code<\/span> in the result can also be used to edit the appointment later.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Schedule an appointment.\n$o_finish_model = new \\WellnessLiving\\Wl\\Appointment\\Book\\Finish\\Finish47Model($o_config);\n$o_finish_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_finish_model->is_backend=1;\n$o_finish_model->k_business='3';\n$o_finish_model->k_location='3';\n\n$o_finish_model->uid='4';\n$o_finish_model->a_book_data=[\n 'dt_date' => '2023-04-04 14:30:00',\n 'i_duration' => 60,\n 'is_backend' => 1,\n 'is_staff_confirm' => 0,\n 'id_class_tab' => \\WellnessLiving\\Wl\\Classes\\Tab\\TabSid::SERVICE, \/\/ Specifies this is an appointment.\n 'k_service' => '2',\n 'uid' => '4'\n];\n\n\/\/ Perform the request.\n$o_finish_model->post();\n\n\/\/ Print the keys of the booked appointment(s).\nforeach($o_finish_model->a_appointment as $a_appointment)\n{\n echo $a_appointment['k_appointment'].\"\\n\";\n}<\/pre>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To book an appointment for a client, you\u2019ll need the client\u2019s 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\u2019ll [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/74"}],"collection":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":25,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/74\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}