Changes

no edit summary
Line 1: Line 1:  
<br><br>
 
<br><br>
Use our developer API to create your own booking interface. You can design any solution you want varying from simpliest 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.
    
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].
   −
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>
+
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>
   −
==Autorization==
+
='''AUTHORIZATION'''=
 
+
<br><br>
Using Simplybook API methods require an authentification. 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 http://user-api.simplybook.me/login service passing your personal API-key. You can copy your API-key at admin interface: go to the 'Plugins' link and select API plugin '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 http://user-api.simplybook.me/login service passing your personal API-key. You can copy your API-key at admin interface: go to the 'Plugins' link and select API plugin 'Settings'. Then you have to init remote access to Simplybook API. Your request should contain the following headers: 'X-Company-Login', 'X-Token'.
    
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.
    
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.
 +
<br><br><br>
 +
='''CLIENT API([https://simplybook.me/api/doc#/admin COMPANY PUBLIC SERVICE])AUTHORIZATION'''=
 +
<br><br>
 +
=='''Authorization from client side code'''==
 +
<br><br>
 +
'''Getting the token-key'''.
 
<br><br>
 
<br><br>
==Client API([https://simplybook.me/api/doc#/admin Company public service])authorization==
  −
<br>
  −
'''Authorization from client side code'''<br><br>
  −
Getting the token-key.<br><br>
   
  <nowiki>var loginClient = new JSONRpcClient({
 
  <nowiki>var loginClient = new JSONRpcClient({
 
'url': 'http://user-api.simplybook.me' + '/login',
 
'url': 'http://user-api.simplybook.me' + '/login',
Line 23: Line 26:  
});
 
});
 
var token = loginClient.getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
 
var token = loginClient.getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
<br><br>Initialization JSON-RPC-client.<br><br>
+
<br><br>
  <nowiki>this.client = new JSONRpcClient({<br>
+
'''Initialization JSON-RPC-client.'''
'url': 'http://user-api.simplybook.me',<br>
+
<br><br>
'headers': {<br>
+
  <nowiki>this.client = new JSONRpcClient({
'X-Company-Login': YOUR_COMPANY_LOGIN,<br>
+
'url': 'http://user-api.simplybook.me',
'X-Token': token<br>
+
'headers': {
},<br>
+
'X-Company-Login': YOUR_COMPANY_LOGIN,
'onerror': function (error) {}<br>
+
'X-Token': token
});</nowiki><br><br>
+
},
'''Authorization from server side code'''<br><br>
+
'onerror': function (error) {}
Getting the token-key.<br><br>
+
});</nowiki>
 +
<br><br>
 +
=='''Authorization from server side code'''==
 +
<br><br>
 +
'''Getting the token-key.'''<br><br>
 
  <nowiki>$loginClient = new JsonRpcClient('http://user-api.simplybook.me' . '/login/');
 
  <nowiki>$loginClient = new JsonRpcClient('http://user-api.simplybook.me' . '/login/');
 
$token = $loginClient->getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
 
$token = $loginClient->getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
 
<br><br>
 
<br><br>
Initialization JSON-RPC-client.
+
'''Initialization JSON-RPC-client.'''
 
<br><br>
 
<br><br>
 
  <nowiki>$client = new JsonRpcClient('http://user-api.simplybook.me' . '/', array(
 
  <nowiki>$client = new JsonRpcClient('http://user-api.simplybook.me' . '/', array(
Line 45: Line 52:  
     )
 
     )
 
));</nowiki>
 
));</nowiki>
 +
<br><br><br>
 +
='''USER/ADMIN API ([https://simplybook.me/api/doc#/admin COMPANY ADMINISTRATION SERVICE]) AUTHORIZATION'''=
 +
<br><br>
 +
=='''Authorization from client side code'''==
 +
<br><br>
 +
'''Getting the token-key.'''
 
<br><br>
 
<br><br>
==User/Admin API ([https://simplybook.me/api/doc#/admin Company Administration Service]) Authorization==
  −
<br><br>'''Authorization from client side code'''<br><br>
  −
Getting the token-key.<br><br>
   
  <nowiki>var loginClient = new JSONRpcClient({
 
  <nowiki>var loginClient = new JSONRpcClient({
 
'url': 'http://user-api.simplybook.me' + '/login',
 
'url': 'http://user-api.simplybook.me' + '/login',
Line 55: Line 65:  
var token = loginClient.getUserToken(YOUR_COMPANY_LOGIN, YOUR_USER_LOGIN, YOUR_USER_PASSWORD);</nowiki>
 
var token = loginClient.getUserToken(YOUR_COMPANY_LOGIN, YOUR_USER_LOGIN, YOUR_USER_PASSWORD);</nowiki>
 
<br><br>
 
<br><br>
Initialization JSON-RPC-client.
+
'''Initialization JSON-RPC-client'''.
 
<br><br>
 
<br><br>
 
  <nowiki>this.client = new JSONRpcClient({
 
  <nowiki>this.client = new JSONRpcClient({
Line 66: Line 76:  
});</nowiki>
 
});</nowiki>
 
<br><br>
 
<br><br>
'''Authorization from server side code'''<br><br>
+
=='''Authorization from server side code'''==
Getting the token-key.<br><br>
+
<br><br>
 +
'''Getting the token-key.'''
 +
<br><br>
 
  <nowiki>$loginClient = new JsonRpcClient('http://user-api.simplybook.me' . '/login/');
 
  <nowiki>$loginClient = new JsonRpcClient('http://user-api.simplybook.me' . '/login/');
 
$token = $loginClient->getUserToken(YOUR_COMPANY_LOGIN, YOUR_USER_LOGIN, YOUR_USER_PASSWORD);</nowiki>
 
$token = $loginClient->getUserToken(YOUR_COMPANY_LOGIN, YOUR_USER_LOGIN, YOUR_USER_PASSWORD);</nowiki>
 
<br><br>
 
<br><br>
Initialization JSON-RPC-client.<br><br>
+
'''Initialization JSON-RPC-client.'''
 +
<br><br>
 
  <nowiki>$client = new JsonRpcClient('http://user-api.simplybook.me' . '/admin/', array(
 
  <nowiki>$client = new JsonRpcClient('http://user-api.simplybook.me' . '/admin/', array(
 
'headers' => array(
 
'headers' => array(
Line 78: Line 91:  
)
 
)
 
));</nowiki>
 
));</nowiki>
 
+
<br><br><br>
==Getting Data from SimplyBook Server==
+
='''GETTING DATA FROM SIMPLYBOOK SERVER'''=
 +
<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 additional fields, 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 additional fields, 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].
    
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>
Code example of getting services list
+
'''Code example of getting services list'''
 +
<br><br>
 
  <nowiki>$services = $client->getEventList();
 
  <nowiki>$services = $client->getEventList();
 
// returns array(array(
 
// returns array(array(
Line 98: Line 113:  
//    'is_public' => 1, - the service is allowed to book by clients
 
//    'is_public' => 1, - the service is allowed to book by clients
 
// ), ...)</nowiki>
 
// ), ...)</nowiki>
Code example of getting service performers list<br><br>
+
<br><br>
 +
'''Code example of getting service performers list'''
 +
<br><br>
 
  <nowiki>$services = $client->getUnitList();
 
  <nowiki>$services = $client->getUnitList();
 
// returns array(array(
 
// returns array(array(
Line 115: Line 132:  
<br><br>
 
<br><br>
 
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>
Code example of getting work days info<br><br>
+
'''Code example of getting work days info'''
 +
<br><br>
 
  <nowiki>$year = 2015;
 
  <nowiki>$year = 2015;
 
$month = 3; // March
 
$month = 3; // March
Line 126: Line 144:  
//    ...
 
//    ...
 
//);</nowiki>
 
//);</nowiki>
Code example of getting start time matrix<br><br>
+
<br><br>
 +
'''Code example of getting start time matrix'''
 +
<br><br>
 
  <nowiki>$dateFrom = '2015-03-03';
 
  <nowiki>$dateFrom = '2015-03-03';
 
$dateTo = '2015-03-04';
 
$dateTo = '2015-03-04';
Line 139: Line 159:  
<br><br>
 
<br><br>
 
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>
Code example of calculating booking end time<br><br>
+
'''Code example of calculating booking end time'''
 +
<br><br>
 
  <nowiki>$startDateTime = '2015-03-03 09:00:00';
 
  <nowiki>$startDateTime = '2015-03-03 09:00:00';
 
$serviceId = 1;
 
$serviceId = 1;
Line 149: Line 170:  
<br><br>
 
<br><br>
 
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>
 +
='''USING OF API SECRET KEY'''=
 
<br><br>
 
<br><br>
==Using of API Secret Key==
   
In some cases the book method may require the confirmation, e.g. if your accept payments from clients you confirm booking only after the payment is already came. The Simplybook API confirmBookng method takes booking-id and secure signature as params (another method which requires secure signature is cancelBookng). For the secure signature generation your secret API-key should be used. See how it can be done in the example below. You can find the secret key at admin interface under 'Settings' link of API plugin in 'Plugins' list.
 
In some cases the book method may require the confirmation, e.g. if your accept payments from clients you confirm booking only after the payment is already came. The Simplybook API confirmBookng method takes booking-id and secure signature as params (another method which requires secure signature is cancelBookng). For the secure signature generation your secret API-key should be used. See how it can be done in the example below. You can find the secret key at admin interface under 'Settings' link of API plugin in 'Plugins' list.
 
+
<br><br>
Code example of service booking and its confirmation using secret API key<br><br>
+
'''Code example of service booking and its confirmation using secret API key'''
 +
<br><br>
 
  <nowiki>$additionalFields = array(
 
  <nowiki>$additionalFields = array(
 
'6740d3bce747107ddb9a789cbb78abf3' => 'value1',  
 
'6740d3bce747107ddb9a789cbb78abf3' => 'value1',  
Line 176: Line 199:  
     }
 
     }
 
}</nowiki>
 
}</nowiki>
Code example of getting additional fields <br><br>
+
<br><br>
 +
'''Code example of getting additional fields'''
 +
<br><br>
 
  <nowiki>$fields = $client->getAdditionalFields($eventId);
 
  <nowiki>$fields = $client->getAdditionalFields($eventId);
 
// returns - array(array(
 
// returns - array(array(
Line 189: Line 214:  
// 'value' => null
 
// 'value' => null
 
// )), ...)</nowiki>
 
// )), ...)</nowiki>
==SimplyBook Plugins==
+
<br><br><br>
 +
='''SIMPLYBOOK PLUGINS'''=
 +
<br><br>
 
If your company specific requires some additional functionality you can activate some of our additional plugins. The complete plugin list with detailed description is avaiable in your admin interface under the 'Plugins' link. After the necessary plugin is enabled the corresponding API methods will be activated so you can use them in your code.
 
If your company specific requires some additional functionality you can activate some of our additional plugins. The complete plugin list with detailed description is avaiable in your admin interface under the 'Plugins' link. After the necessary plugin is enabled the corresponding API methods will be activated so you can use them in your code.
 
+
<br><br><br>
==Booking Functionality Codeflow==
+
='''BOOKING FUNCTIONALITY CODEFLOW'''=
 
+
<br><br>
 
Authorize in Simplybook API using '''loginClient.getToken(companyLogin, apiKey);''' function.
 
Authorize in Simplybook API using '''loginClient.getToken(companyLogin, apiKey);''' function.
   Line 215: Line 242:       −
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.<br><br>