In this article, we will guide you through the process of creating a payload and hashstring to access the BookingLive API effectively. By following these steps, you can ensure secure and efficient API calls.
Step 1: Add a Secret Key
To begin, you'll need to integrate a secret key into your system, which is vital for generating the hashstring.
1. Open Your Site: Navigate to your BookingLive site and log into the admin section.
2. Access General Settings: Go to General Settings and select Add-ons.
3. Input the Secret Key: Click on the API tab and enter your secret key.
4. Select Hash Method: Ensure that the hash method is set to sha256.
5. Save Changes: Click "Save and Close".
Step 2: Use the PHP Class to Generate the Payload and Hash String
Once you have configured the secret key, you can use the following PHP class to generate the payload and hashstring needed to communicate with the API.
<?php class generateApiCalls { private $secret_key = 'bookinglive'; private $base_url = 'http://[your-domain]/api/plain/'; public function generate($apiType,$payload = array()) { $arrJson = array( 'Type' => $apiType, 'Payload' => json_encode($payload) ); $httpQuery = http_build_query($arrJson); $hashstring = hash_hmac('sha256',$httpQuery,$this ->secret_key); $httpQuery .= '&HashString='.$hashstring; return $this->base_url.'?'.$httpQuery; } }
This code will facilitate the generation of API calls by creating a unique URL with the necessary authentication appended.
Step 3: Example of Calling the StartNewOrder API
For practical application, let’s look at an example where we call the StartNewOrder API. The payload for this API contains relevant member and order details.
$payload = array( 'Member' => array( 'FirstName' => 'User1', 'Surname' => 'User1', 'Email' => 'user1@user1.com', 'Company' => 'Bookinglive', 'Job Title' => 'Developer' ), 'OrderItems' => array( array( 'ProductID' => 5, 'ProductClassName' => 'ProductFixedEvent', 'EventID' => 1157, 'Quantity' => '1' ) ), "Transactions" => array( array( "Type" => "Cash", "Amount" => "20.0" ) ), 'SendConfirmationEmail' => false, );
$apiCall = new generateApiCalls();
echo $apiCall = $apiCall->generate('APIStartAndCompeteOrder' ,$payload );
Executing this code will return the whole URL so you can access the API.