In this article we will explain how to create a payload and hashstring to access the BookingLive API

To do so first we need to add a secret key in the system.


Open your site and log into the admin section.

Go to General Settings - > Add ons

Select the API tab and enter the secret key.

Leave the hash method to be sha256.


Click "Save and close".


After you have set the secret key we can use this php class to generate the payload and the hash string.


<?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;
    }
}


Using this code you can easily create call to the API. Here an example of how to call StartNewOrder API.


$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