User API guide: Difference between revisions

No edit summary
Marked this version for translation
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>
<!--T:1-->
{{#seo:
{{#seo:
|title=User API guide - SimplyBook.me
|title=User API guide - SimplyBook.me
Line 11: Line 12:


<translate>
<translate>
<!--T:2-->
Use our developer API to create your own booking interface. You can design any solution you want varying from the simplest widget to multifunctional application with functionality customized according to your business specific.
Use our developer API to create your own booking interface. You can design any solution you want varying from the simplest widget to multifunctional application with functionality customized according to your business specific.


<!--T:3-->
Simplybook Application Programming Interface uses [https://en.wikipedia.org/wiki/JSON-RPC#Version_2.0 JSON-RPC 2.0 protocol].
Simplybook Application Programming Interface uses [https://en.wikipedia.org/wiki/JSON-RPC#Version_2.0 JSON-RPC 2.0 protocol].


<!--T:4-->
See [https://simplybook.me/api_example/index.html an example of API-based booking interface], and also read [https://simplybook.me/api_example/scheduler.js the source code] of this solution.
See [https://simplybook.me/api_example/index.html an example of API-based booking interface], and also read [https://simplybook.me/api_example/scheduler.js the source code] of this solution.
<br><br><be>
<br><br><be>
Line 22: Line 26:
<translate>
<translate>


<!--T:5-->
='''AUTHORIZATION'''=
='''AUTHORIZATION'''=
<br><br>
<br><br>
Line 30: Line 35:
<translate>
<translate>


<!--T:6-->
Getting the access-token can be implemented either from client side or from your server which is the more secure solution.
Getting the access-token can be implemented either from client side or from your server which is the more secure solution.


<!--T:7-->
You may use [https://simplybook.me/api_example/json-rpc-client.js javascript JSON-RPC-client library] and [https://simplybook.me/api_example/JsonRpcClient.zip php JSON-RPC-client library] from our examples for your own solution development.
You may use [https://simplybook.me/api_example/json-rpc-client.js javascript JSON-RPC-client library] and [https://simplybook.me/api_example/JsonRpcClient.zip php JSON-RPC-client library] from our examples for your own solution development.


<!--T:8-->
Please note access-token has one hour one time. This is done for security reasons. You will need to regenerate it at least once per hour.
Please note access-token has one hour one time. This is done for security reasons. You will need to regenerate it at least once per hour.
<br><br><br>
<br><br><br>
Line 41: Line 49:
<translate>
<translate>


<!--T:9-->
='''CLIENT API([https://simplybook.me/api/doc#/admin COMPANY PUBLIC SERVICE])AUTHORIZATION'''=
='''CLIENT API([https://simplybook.me/api/doc#/admin COMPANY PUBLIC SERVICE])AUTHORIZATION'''=
<br><br>
<br><br>
Line 123: Line 132:
<translate>
<translate>


<!--T:10-->
='''GETTING DATA FROM SIMPLYBOOK SERVER'''=
='''GETTING DATA FROM SIMPLYBOOK SERVER'''=
<br><br>
<br><br>
Line 131: Line 141:
<translate>
<translate>


<!--T:11-->
So the first thing you should display is the list of services and the list of employes. Get this data by getEventList and getUnitList methods. They both return a list with complete information about each item in it, so you have many possibilities how to display services and employees at your page. To make employee filtration use unit_map property of the service list, it contains the info about employees who can provide the selected service.
So the first thing you should display is the list of services and the list of employes. Get this data by getEventList and getUnitList methods. They both return a list with complete information about each item in it, so you have many possibilities how to display services and employees at your page. To make employee filtration use unit_map property of the service list, it contains the info about employees who can provide the selected service.
<br><be>
<br><be>
Line 138: Line 149:
<translate>
<translate>


<!--T:12-->
'''Code example of getting services list'''
'''Code example of getting services list'''
<br><br>
<br><br>
Line 176: Line 188:
<translate>
<translate>


<!--T:13-->
The next step to a client is to pick a date and time of his service. We've used a Bootstrap date-picker in API-usage example, you can also use this or any other calendar. To set your calendar first date use getFirstWorkingDay method. It can take employee id as a parameter and returns the next date when the selected employee (or any employee in the company by default) is avaiable for booking. To show time slots inside a selected date you need getWorkCalendar and getStartTimeMatrix methods. The first method give you an information about working day start and end time, and about day-offs. And the second one returns the list of time-slots which can be booked for a certain date.
The next step to a client is to pick a date and time of his service. We've used a Bootstrap date-picker in API-usage example, you can also use this or any other calendar. To set your calendar first date use getFirstWorkingDay method. It can take employee id as a parameter and returns the next date when the selected employee (or any employee in the company by default) is avaiable for booking. To show time slots inside a selected date you need getWorkCalendar and getStartTimeMatrix methods. The first method give you an information about working day start and end time, and about day-offs. And the second one returns the list of time-slots which can be booked for a certain date.
<br><be>
<br><be>
Line 183: Line 196:
<translate>
<translate>


<!--T:14-->
'''Code example of getting work days info'''
'''Code example of getting work days info'''
<br><br>
<br><br>
Line 200: Line 214:
<translate>
<translate>


<!--T:15-->
'''Code example of getting start time matrix'''
'''Code example of getting start time matrix'''
<br><br>
<br><br>
Line 218: Line 233:
<translate>
<translate>


<!--T:16-->
Another usefull method you may need is calculateEndTime. Each service can have its own duration, also your company's employees possible have different work schedule form day to day. So using this method you can show to a client an end date and time of the service he've booked in a correct way.
Another usefull method you may need is calculateEndTime. Each service can have its own duration, also your company's employees possible have different work schedule form day to day. So using this method you can show to a client an end date and time of the service he've booked in a correct way.
<br><be>
<br><be>
Line 225: Line 241:
<translate>
<translate>


<!--T:17-->
'''Code example of calculating booking end time'''
'''Code example of calculating booking end time'''
<br><br>
<br><br>
Line 239: Line 256:
<translate>
<translate>


<!--T:18-->
When a client clicks confirm booking button you have to call book method. This is the main function which performs all necessary validations and registers a new booking in Simplybook system. It takes information about booking, client data like name and phone and some additional params. See all params descriptions of this method in [https://simplybook.me/api/doc API functions list]. The book method responce contains an uniqe code and other details of the new booking or the list of errors if some problems occured, so you can use this information to show booking result to a client in convinient and intuitive way.
When a client clicks confirm booking button you have to call book method. This is the main function which performs all necessary validations and registers a new booking in Simplybook system. It takes information about booking, client data like name and phone and some additional params. See all params descriptions of this method in [https://simplybook.me/api/doc API functions list]. The book method responce contains an uniqe code and other details of the new booking or the list of errors if some problems occured, so you can use this information to show booking result to a client in convinient and intuitive way.
<br><br><be>
<br><br><be>
Line 246: Line 264:
<translate>
<translate>


<!--T:19-->
='''USING OF API SECRET KEY'''=
='''USING OF API SECRET KEY'''=
<br><br>
<br><br>
Line 255: Line 274:
<translate>
<translate>


<!--T:20-->
'''Code example of service booking and its confirmation using secret API key'''
'''Code example of service booking and its confirmation using secret API key'''
<br><br>
<br><br>
Line 269: Line 289:
$bookingsInfo = $client->book($eventId, $unitId, $date, $time, $clientData, $additionalFields);
$bookingsInfo = $client->book($eventId, $unitId, $date, $time, $clientData, $additionalFields);


<!--T:21-->
if ($bookingsInfo->require_confirm) {
if ($bookingsInfo->require_confirm) {
   foreach ($bookingsInfo->bookings as $booking) {
   foreach ($bookingsInfo->bookings as $booking) {
Line 285: Line 306:
<translate>
<translate>


<!--T:22-->
'''Code example of getting intake forms'''
'''Code example of getting intake forms'''
<br><br>
<br><br>
Line 305: Line 327:
<translate>
<translate>


<!--T:23-->
='''SIMPLYBOOK CUSTOM FEATURES'''=
='''SIMPLYBOOK CUSTOM FEATURES'''=
<br><br>
<br><br>
Line 314: Line 337:
<translate>
<translate>


<!--T:24-->
='''BOOKING FUNCTIONALITY CODEFLOW'''=
='''BOOKING FUNCTIONALITY CODEFLOW'''=
<br><br>
<br><br>
Authorize in Simplybook API using '''loginClient.getToken(companyLogin, apiKey);''' function.
Authorize in Simplybook API using '''loginClient.getToken(companyLogin, apiKey);''' function.


<!--T:25-->
Check if Service categories Custom Feature is activated by [https://simplybook.me/en/api/doc#isPluginActivated isPluginActivated("event_category")]  if yes then display list of categories [https://simplybook.me/en/api/doc#getCategoriesList getCategoriesList()].
Check if Service categories Custom Feature is activated by [https://simplybook.me/en/api/doc#isPluginActivated isPluginActivated("event_category")]  if yes then display list of categories [https://simplybook.me/en/api/doc#getCategoriesList getCategoriesList()].


Line 324: Line 349:
<translate>
<translate>


<!--T:26-->
Get list of services (events) and performers (units) using [https://simplybook.me/en/api/doc#getEventList getEventList()] and [https://simplybook.me/en/api/doc#getUnitList getUnitList()] functions. If "unit_map" array is available for service it means this service can be provided by given performers only.
Get list of services (events) and performers (units) using [https://simplybook.me/en/api/doc#getEventList getEventList()] and [https://simplybook.me/en/api/doc#getUnitList getUnitList()] functions. If "unit_map" array is available for service it means this service can be provided by given performers only.


Line 330: Line 356:
<translate>
<translate>


<!--T:27-->
If Any Employee Selector Custom Feature is activated [https://simplybook.me/en/api/doc#isPluginActivated isPluginActivated("any_unit")] and no special duration is set for service-performer pair in "unit_map" array then user should be allowed to select Any provider option or choose provider manually. But manual selection of performers should not be possible if [https://simplybook.me/en/api/doc#getCompanyParam getCompanyParam("any_unit__hide_other_units")] is enabled.
If Any Employee Selector Custom Feature is activated [https://simplybook.me/en/api/doc#isPluginActivated isPluginActivated("any_unit")] and no special duration is set for service-performer pair in "unit_map" array then user should be allowed to select Any provider option or choose provider manually. But manual selection of performers should not be possible if [https://simplybook.me/en/api/doc#getCompanyParam getCompanyParam("any_unit__hide_other_units")] is enabled.


<!--T:28-->
Use [https://simplybook.me/en/api/doc#getStartTimeMatrix getStartTimeMatrix ($from as current date, $to as current date, $eventId, $unitId, $count as selected participants value )] to get available timeslots for given date. '''$unitId''' should be null if Any employee option is selected.
Use [https://simplybook.me/en/api/doc#getStartTimeMatrix getStartTimeMatrix ($from as current date, $to as current date, $eventId, $unitId, $count as selected participants value )] to get available timeslots for given date. '''$unitId''' should be null if Any employee option is selected.


<!--T:29-->
If Any Employee selector is active and Any employee was selected call [https://simplybook.me/en/api/doc#getAvailableUnits getAvailableUnits($eventId, $dateTime, $count)] to get available $unitId
If Any Employee selector is active and Any employee was selected call [https://simplybook.me/en/api/doc#getAvailableUnits getAvailableUnits($eventId, $dateTime, $count)] to get available $unitId


Line 341: Line 370:




<!--T:30-->
If Intake Forms Custom Feature is activated [https://simplybook.me/en/api/doc#isPluginActivated isPluginActivated("event_field")] call [https://simplybook.me/en/api/doc#getAdditionalFields getAdditionalFields($eventId)] function to get list of fields for client to fill.
If Intake Forms Custom Feature is activated [https://simplybook.me/en/api/doc#isPluginActivated isPluginActivated("event_field")] call [https://simplybook.me/en/api/doc#getAdditionalFields getAdditionalFields($eventId)] function to get list of fields for client to fill.


<!--T:31-->
Call [https://simplybook.me/en/api/doc#book book($eventId, $unitId, $date, $time, $clientData, $additional, $count, $batchId)] to make a booking.
Call [https://simplybook.me/en/api/doc#book book($eventId, $unitId, $date, $time, $clientData, $additional, $count, $batchId)] to make a booking.


<!--T:32-->
<br><be>
<br><be>


</translate>
</translate>