User API guide: Difference between revisions
No edit summary |
Marked this version for translation |
||
| Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
<translate> | <translate> | ||
<!--T:33--> | |||
{{#seo: | {{#seo: | ||
|title=User API guide - SimplyBook.me | |title=User API guide - SimplyBook.me | ||
| Line 11: | Line 12: | ||
<translate> | <translate> | ||
<!--T:34--> | |||
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:35--> | |||
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:36--> | |||
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><br> | <br><br><br> | ||
| Line 21: | Line 25: | ||
<translate> | <translate> | ||
<!--T:37--> | |||
='''AUTHORIZATION'''= | ='''AUTHORIZATION'''= | ||
<br><br> | <br><br> | ||
Using Simplybook API methods require an authentication. To authorize in Simplybook API you need to get an access key — access-token. In order to get this access-token you should call the JSON-RPC method getToken on https://user-api.simplybook.me/login service passing your personal API-key. You can copy your API-key at admin interface: go to the 'Custom Features' link and select API Custom Feature 'Settings'. Then you have to init remote access to Simplybook API. Your request should contain the following headers: 'X-Company-Login', 'X-Token'. | Using Simplybook API methods require an authentication. To authorize in Simplybook API you need to get an access key — access-token. In order to get this access-token you should call the JSON-RPC method getToken on https://user-api.simplybook.me/login service passing your personal API-key. You can copy your API-key at admin interface: go to the 'Custom Features' link and select API Custom Feature 'Settings'. Then you have to init remote access to Simplybook API. Your request should contain the following headers: 'X-Company-Login', 'X-Token'. | ||
<!--T:38--> | |||
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. | ||
| Line 30: | Line 36: | ||
<translate> | <translate> | ||
<!--T:39--> | |||
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:40--> | |||
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 38: | Line 46: | ||
<translate> | <translate> | ||
<!--T:41--> | |||
='''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 79: | Line 88: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:42--> | |||
='''USER/ADMIN API ([https://simplybook.me/api/doc#/admin COMPANY ADMINISTRATION SERVICE]) AUTHORIZATION'''= | ='''USER/ADMIN API ([https://simplybook.me/api/doc#/admin COMPANY ADMINISTRATION SERVICE]) AUTHORIZATION'''= | ||
<br><br> | <br><br> | ||
| Line 94: | Line 104: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:43--> | |||
'''Initialization JSON-RPC-client'''. | '''Initialization JSON-RPC-client'''. | ||
<br><br> | <br><br> | ||
| Line 108: | Line 119: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:44--> | |||
=='''Authorization from server side code'''== | =='''Authorization from server side code'''== | ||
<br><br> | <br><br> | ||
| Line 127: | Line 139: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:45--> | |||
='''GETTING DATA FROM SIMPLYBOOK SERVER'''= | ='''GETTING DATA FROM SIMPLYBOOK SERVER'''= | ||
<br><br> | <br><br> | ||
A booking page usually is a page where clients choose service they need, an employee and a time of their meeting. Then a client enters some contact info and confirms the booking. The more complex solutions may include filling different intake forms, making some group or multi-times booking and so on. Lets describe the workflow of creation the simpliest booking page. Then if you need to add some extra functionality to your page, see here the full list of [https://simplybook.me/api/doc Simplybook API methods]. | A booking page usually is a page where clients choose service they need, an employee and a time of their meeting. Then a client enters some contact info and confirms the booking. The more complex solutions may include filling different intake forms, making some group or multi-times booking and so on. Lets describe the workflow of creation the simpliest booking page. Then if you need to add some extra functionality to your page, see here the full list of [https://simplybook.me/api/doc Simplybook API methods]. | ||
<!--T:46--> | |||
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><br> | <br><br> | ||
| Line 136: | Line 150: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:47--> | |||
'''Code example of getting services list''' | '''Code example of getting services list''' | ||
<br><br> | <br><br> | ||
| Line 155: | Line 170: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:48--> | |||
'''Code example of getting service performers list''' | '''Code example of getting service performers list''' | ||
<br><br> | <br><br> | ||
| Line 175: | Line 191: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:49--> | |||
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><br> | <br><br> | ||
| Line 182: | Line 199: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<nowiki>$year = 2015; | <!--T:50--> | ||
<nowiki>$year = 2015; | |||
$month = 3; // March | $month = 3; // March | ||
$performerId = 1; // Can be null | $performerId = 1; // Can be null | ||
| Line 208: | Line 226: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:51--> | |||
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><br> | <br><br> | ||
| Line 222: | Line 241: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:52--> | |||
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><br> | <br><br><br> | ||
| Line 227: | Line 247: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:53--> | |||
='''USING OF API SECRET KEY'''= | ='''USING OF API SECRET KEY'''= | ||
<br><br> | <br><br> | ||
| Line 234: | Line 255: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:54--> | |||
'''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 248: | Line 270: | ||
$bookingsInfo = $client->book($eventId, $unitId, $date, $time, $clientData, $additionalFields); | $bookingsInfo = $client->book($eventId, $unitId, $date, $time, $clientData, $additionalFields); | ||
<!--T:55--> | |||
if ($bookingsInfo->require_confirm) { | if ($bookingsInfo->require_confirm) { | ||
foreach ($bookingsInfo->bookings as $booking) { | foreach ($bookingsInfo->bookings as $booking) { | ||
| Line 262: | Line 285: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:56--> | |||
'''Code example of getting intake forms''' | '''Code example of getting intake forms''' | ||
<br><br> | <br><br> | ||
| Line 280: | Line 304: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:57--> | |||
='''SIMPLYBOOK CUSTOM FEATURES'''= | ='''SIMPLYBOOK CUSTOM FEATURES'''= | ||
<br><br> | <br><br> | ||
| Line 289: | Line 314: | ||
<!--T:58--> | |||
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()]. | ||
<!--T:59--> | |||
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 298: | Line 325: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:60--> | |||
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:61--> | |||
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:62--> | |||
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 310: | Line 340: | ||
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:63--> | |||
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:64--> | |||
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:65--> | |||
<br><br> | <br><br> | ||
</translate> | </translate> | ||