User API guide/da: Difference between revisions

From SimplyBook.me
FuzzyBot (talk | contribs)
Updating to match new version of source page
Tags: Mobile edit Mobile web edit
Created page with "Bemærk, at adgangstokenet er gyldigt i én time. Dette er af sikkerhedsmæssige årsager. Du skal genoprette det mindst én gang i timen. <br><br><br>"
Line 1: Line 1:
<languages/>
<languages/>
<div lang="en" dir="ltr" class="mw-content-ltr">
{{#seo: |title=Brugervejledning til API - SimplyBook.me |description=Brug SimplyBook.me Bruger-API til at oprette avancerede integrationer. Følg vores vejledning for problemfri implementering. Få mere at vide her! |titlemode=tilføj |keywords=faq, ofte stillede spørgsmål, reservationssoftware, spørgsmål om aftalesystem, onlineaftaler, kalendersoftware, reservationssystem, reservationskalender, planlægningssoftware, onlineaftaleplanlægning, onlineplanlægning, plugins, tilpassede funktioner, link til tilpasset reservationsside, domænenavn, tilpasset domænenavn, tilpasset url }}
{{#seo:
|title=User API guide - SimplyBook.me
|description=Use the SimplyBook.me User API to create advanced integrations. Follow our guide for seamless implementation. Learn more here!
|titlemode=append
|keywords=faq, frequently asked questions, booking software, appointment system questions, appointments online, calendar software, booking system, booking calendar, scheduling software, online appointment scheduling, online scheduling, plugins, custom features, custom booking page link, domain name, custom domain name, custom url
}}
</div>
<br><br>
<br><br>


<div lang="en" dir="ltr" class="mw-content-ltr">
Brug vores udvikler-API til at oprette din egen bookinggrænseflade. Du kan designe enhver løsning, du ønsker, lige fra den enkleste widget til multifunktionelle applikationer med funktionalitet, der er tilpasset din virksomheds specifikke behov.
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.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Simplybook Application Programming Interface bruger [https://en.wikipedia.org/wiki/JSON-RPC#Version_2.0 JSON-RPC 2.0-protokollen].
Simplybook Application Programming Interface uses [https://en.wikipedia.org/wiki/JSON-RPC#Version_2.0 JSON-RPC 2.0 protocol].
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Se [https://simplybook.me/api_example/index.html et eksempel på en API-baseret bookinggrænseflade], og læs også [https://simplybook.me/api_example/scheduler.js kildekoden] til denne løsning.
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>
</div>




<div lang="en" dir="ltr" class="mw-content-ltr">
= '''AUTORISATION''' =
='''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'.
Brug af Simplybook API-metoder kræver godkendelse. For at godkende i Simplybook API skal du få en adgangsnøgle adgangstoken. For at få denne adgangstoken skal du kalde JSON-RPC-metoden getToken https://user-api.simplybook.me/login service og indtaste din personlige API-nøgle. Du kan kopiere din API-nøgle i admin-grænsefladen: gå til linket 'Custom Features' og vælg API Custom Feature 'Settings'. Derefter skal du initialisere fjernadgang til Simplybook API. Din anmodning skal indeholde følgende headere: 'X-Company-Login', 'X-Token'.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Adgangstoken kan implementeres enten fra klientsiden eller fra din server, hvilket er den mest sikre løsning.
Getting the access-token can be implemented either from client side or from your server which is the more secure solution.
</div>




<div lang="en" dir="ltr" class="mw-content-ltr">
Du kan bruge [https://simplybook.me/api_example/json-rpc-client.js javascript JSON-RPC-klientbibliotek] og [https://simplybook.me/api_example/JsonRpcClient.zip php JSON-RPC-klientbibliotek] fra vores eksempler til udvikling af din egen løsning.
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.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Bemærk, at adgangstokenet er gyldigt i én time. Dette er af sikkerhedsmæssige årsager. Du skal genoprette det mindst én gang i timen.
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>
</div>




<div lang="en" dir="ltr" class="mw-content-ltr">
= '''KLIENT-API ([https://simplybook.me/api/doc#/admin OFFENTLIG TJENESTE]) AUTORISATION''' =
='''CLIENT API([https://simplybook.me/api/doc#/admin COMPANY PUBLIC SERVICE])AUTHORIZATION'''=
<br><br>
<br><br>
=='''Authorization from client side code'''==
== '''Autorisation fra klientens kode''' ==
<br><br>
<br><br>
'''Getting the token-key'''.
'''Hent token-nøglen'''.
<br><br>
<br><br>
  <nowiki>var loginClient = new JSONRpcClient({
  <nowiki>var loginClient = new JSONRpcClient({
Line 58: Line 36:
var token = loginClient.getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
var token = loginClient.getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
<br><br>
<br><br>
'''Initialization JSON-RPC-client.'''
'''Initialisering af JSON-RPC-klient.'''
<br><br>
<br><br>
  <nowiki>this.client = new JSONRpcClient({
  <nowiki>this.client = new JSONRpcClient({
Line 69: Line 47:
});</nowiki>
});</nowiki>
<br><br>
<br><br>
=='''Authorization from server side code'''==
== '''Autorisation fra serverkode''' ==
<br><br>
<br><br>
'''Getting the token-key.'''<br><br>
'''Hentning af token-nøglen.'''<br><br>
  <nowiki>$loginClient = new JsonRpcClient('https://user-api.simplybook.me' . '/login/');
  <nowiki>$loginClient = new JsonRpcClient('https://user-api.simplybook.me' . '/login/');
$token = $loginClient->getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
$token = $loginClient-&gt;getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);</nowiki>
<br><br>
<br><br>
'''Initialization JSON-RPC-client.'''
'''Initialisering af JSON-RPC-klient.'''
<br><br>
<br><br>
  <nowiki>$client = new JsonRpcClient('https://user-api.simplybook.me' . '/', array(
  <nowiki>$client = new JsonRpcClient('https://user-api.simplybook.me' . '/', array(
    'headers' => array(
  'headers' =&gt; array(
        'X-Company-Login: ' . YOUR_COMPANY_LOGIN,
      'X-Company-Login: ' . YOUR_COMPANY_LOGIN,
        'X-Token: ' . $token
      'X-Token: ' . $token
    )
  )
));</nowiki>
));</nowiki>
<br><br><br>
<br><br><br>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
= '''BRUGER/ADMIN API ([https://simplybook.me/api/doc#/admin VIRKSOMHEDSADMINISTRATIONSTJENESTE]) AUTORISATION''' =
='''USER/ADMIN API ([https://simplybook.me/api/doc#/admin COMPANY ADMINISTRATION SERVICE]) AUTHORIZATION'''=
<br><br>
<br><br>
=='''Authorization from client side code'''==
== '''Autorisation fra klientens kode''' ==
<br><br>
<br><br>
'''Getting the token-key.'''
'''Hent token-nøglen.'''
<br><br>
<br><br>
  <nowiki>var loginClient = new JSONRpcClient({
  <nowiki>var loginClient = new JSONRpcClient({
Line 99: Line 75:
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>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Revision as of 12:20, 15 May 2025



Brug vores udvikler-API til at oprette din egen bookinggrænseflade. Du kan designe enhver løsning, du ønsker, lige fra den enkleste widget til multifunktionelle applikationer med funktionalitet, der er tilpasset din virksomheds specifikke behov.

Simplybook Application Programming Interface bruger JSON-RPC 2.0-protokollen.

Se et eksempel på en API-baseret bookinggrænseflade, og læs også kildekoden til denne løsning.



AUTORISATION



Brug af Simplybook API-metoder kræver godkendelse. For at godkende i Simplybook API skal du få en adgangsnøgle — adgangstoken. For at få denne adgangstoken skal du kalde JSON-RPC-metoden getToken på https://user-api.simplybook.me/login service og indtaste din personlige API-nøgle. Du kan kopiere din API-nøgle i admin-grænsefladen: gå til linket 'Custom Features' og vælg API Custom Feature 'Settings'. Derefter skal du initialisere fjernadgang til Simplybook API. Din anmodning skal indeholde følgende headere: 'X-Company-Login', 'X-Token'.

Adgangstoken kan implementeres enten fra klientsiden eller fra din server, hvilket er den mest sikre løsning.


Du kan bruge javascript JSON-RPC-klientbibliotek og php JSON-RPC-klientbibliotek fra vores eksempler til udvikling af din egen løsning.

Bemærk, at adgangstokenet er gyldigt i én time. Dette er af sikkerhedsmæssige årsager. Du skal genoprette det mindst én gang i timen.



KLIENT-API (OFFENTLIG TJENESTE) AUTORISATION



Autorisation fra klientens kode



Hent token-nøglen.

var loginClient = new JSONRpcClient({
	'url': 'https://user-api.simplybook.me' + '/login',
	'onerror': function (error) {},
});
var token = loginClient.getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);



Initialisering af JSON-RPC-klient.

this.client = new JSONRpcClient({
	'url': 'https://user-api.simplybook.me',
	'headers': {
		'X-Company-Login': YOUR_COMPANY_LOGIN,
		'X-Token': token
	},
	'onerror': function (error) {}
});



Autorisation fra serverkode



Hentning af token-nøglen.

$loginClient = new JsonRpcClient('https://user-api.simplybook.me' . '/login/');
$token = $loginClient->getToken(YOUR_COMPANY_LOGIN, YOUR_API_KEY);



Initialisering af JSON-RPC-klient.

$client = new JsonRpcClient('https://user-api.simplybook.me' . '/', array(
   'headers' => array(
       'X-Company-Login: ' . YOUR_COMPANY_LOGIN,
       'X-Token: ' . $token
   )
));




BRUGER/ADMIN API (VIRKSOMHEDSADMINISTRATIONSTJENESTE) AUTORISATION



Autorisation fra klientens kode



Hent token-nøglen.

var loginClient = new JSONRpcClient({
'url': 'https://user-api.simplybook.me' + '/login',
'onerror': function (error) {},
});
var token = loginClient.getUserToken(YOUR_COMPANY_LOGIN, YOUR_USER_LOGIN, YOUR_USER_PASSWORD);



Initialization JSON-RPC-client.

this.client = new JSONRpcClient({
'url': 'https://user-api.simplybook.me' + '/admin/',
'headers': {
'X-Company-Login': YOUR_COMPANY_LOGIN,
'X-User-Token': token
},
'onerror': function (error) {}
});



Authorization from server side code



Getting the token-key.

$loginClient = new JsonRpcClient('https://user-api.simplybook.me' . '/login/');
$token = $loginClient->getUserToken(YOUR_COMPANY_LOGIN, YOUR_USER_LOGIN, YOUR_USER_PASSWORD);



Initialization JSON-RPC-client.

$client = new JsonRpcClient('https://user-api.simplybook.me' . '/admin/', array(
'headers' => array(
'X-Company-Login: ' . YOUR_COMPANY_LOGIN,
'X-User-Token: ' . $token
)
));




GETTING DATA FROM SIMPLYBOOK SERVER



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 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.

Code example of getting services list

$services = $client->getEventList();
// returns array(array(
//     'id' => 1, - service id
//     'name' => 'Service 1', - service's name
//     'description' => 'Describe your service...', - service description
//     'duration' => 60, - service duration
//     'hide_duration' => 0, - Hide duration to clients flag,
//     'picture' => null, - file name of picture or null
//     'picture_path' => '/uploads/apidemo/event__picture/small/', - full path to picture,
//     'position' => 1 - service position
//     'is_active' => 1, - the service is activated
//     'is_public' => 1, - the service is allowed to book by clients
// ), ...)



Code example of getting service performers list

$services = $client->getUnitList();
// returns array(array(
//    'id' => 1, - performer id
//    'name' => 'Provider 1', - performer name
//    'phone' => '111111111', - perfomer phone number
//    'description' => 'Describe your performer...', - performer description
//    'email' => 'test@gmail.com', - perfomer email,
//    'is_active' => 1, - the performer is activated
//    'is_visible' => 1, - the perfomer is visible for clients,
//    'picture' => null, - file name of picture or null,
//    'picure_path' => '/uploads/apidemo/unit_group__picture/small/', - full path to picture
//    'position' => 1, - performer position
//    'qty' => 1, performer quantity
// ), ...)



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.

Code example of getting work days info

$year = 2015; $month = 3; // March $performerId = 1; // Can be null $workDaysInfo = $client->getWorkCalendar($year, $month, $performerId); // returns array( // '2015-03-01' => array('from' => '09:00:00', 'to' => '18:00:00', 'is_day_off' => 0), // '2015-03-02' => array('from' => '09:00:00', 'to' => '18:00:00', 'is_day_off' => 0), // ... //);

Code example of getting start time matrix

$dateFrom = '2015-03-03';
$dateTo = '2015-03-04';
$serviceId = 1;
$performerId = 1;
$qty = 1;
$availableTime = $client->getStartTimeMatrix($dateFrom, $dateTo, $serviceId, $performerId, $qty);
// returns array(
//     '2015-03-03' => array('09:00:00', '09:30:00', '10:00:00', ....),
//     '2015-03-04' => array('09:00:00', '09:30:00', '10:00:00', ....),
//);



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.

Code example of calculating booking end time

$startDateTime = '2015-03-03 09:00:00';
$serviceId = 1;
$performerId = 1;
$availableTime = $client->calculateEndTime($startDateTime, $serviceId, $performerId);
// returns '2015-03-03 10:00:00'



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 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.


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 Custom Feature in 'Custom Features' list.

Code example of service booking and its confirmation using secret API key

$additionalFields = array(
	'6740d3bce747107ddb9a789cbb78abf3' => 'value1', 
	'b0657bafaec7a2c9800b923f959f8163' => 'value2'
);
$clientData = array(
	'name' => 'Client name',
	'email' => 'client@email.com',
	'phone' => '+13152108338'
);
		
$bookingsInfo = $client->book($eventId, $unitId, $date, $time, $clientData, $additionalFields);
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
if ($bookingsInfo->require_confirm) {
   foreach ($bookingsInfo->bookings as $booking) {
	   $sign = md5($booking->id . $booking->hash . YOUR_API_SECRET_KEY);
	   $result = $client->confirmBooking($booking->id, $sign);
	   echo '
Confirm result
';
	   var_dump($result);
    }
}



Code example of getting intake forms

$fields = $client->getAdditionalFields($eventId);
// returns - array(array(
//		'name' => 'b0657bafaec7a2c9800b923f959f8163', - field name
//		'title' => 'Test digits', - field title
//		'type' => 'digits', - field type
//		'values' => null, - available values for select field type
//		'default' => null, - default value for field
//		'is_null' => null, - is filed nullable
//		'on_main_page' => 1, 
//		'pos' => 1, - field position
//		'value' => null
// )), ...)




SIMPLYBOOK CUSTOM FEATURES



If your company specific requires some additional functionality you can activate some of our additional Custom Features. The complete Custom Features list with detailed description is avaiable in your admin interface under the 'Custom Feature' link. After the necessary Custom Feature is enabled the corresponding API methods will be activated so you can use them in your code.


BOOKING FUNCTIONALITY CODEFLOW



Authorize in Simplybook API using loginClient.getToken(companyLogin, apiKey); function.


Check if Service categories Custom Feature is activated by isPluginActivated("event_category") if yes then display list of categories getCategoriesList().


Get list of services (events) and performers (units) using getEventList() and getUnitList() functions. If "unit_map" array is available for service it means this service can be provided by given performers only.


If Any Employee Selector Custom Feature is activated 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 getCompanyParam("any_unit__hide_other_units") is enabled.


Use 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.


If Any Employee selector is active and Any employee was selected call getAvailableUnits($eventId, $dateTime, $count) to get available $unitId


If Intake Forms Custom Feature is activated isPluginActivated("event_field") call getAdditionalFields($eventId) function to get list of fields for client to fill.