PHP Examples

The following examples are ready to use PHP code pieces for page, page block, and app function.

Page

// Set the content type to JSON
header('Content-Type: application/json');

// Getting the action parameter
$action = $_GET['action'];

// Checking the action of the parameter
// If it is not 'activate', then echo unsuccessful JSON response.
if (empty($action) || $action != 'activate') {
    echo json_encode([
        'success' => false,
        'message' => 'The "action" is not supported!'
    ]);
}

// Activating Lead App
// Initialize the array
$data = [];

// Activation type value: page
$data['activation_type'] = 'page';

// API key
$data['api_key'] = $_GET['API_key']; // Grab it from the GET params

// Lead App configuration

// Lead App name
$data['config']['name'] = 'My Lead App';

// Access URL
$data['config']['url'] = 'https://www.example.com/my/app';

// Location is one of the following:
// dashboard, statistics, campaigns, agents_mng, calling_list_management, product, b2b_mng, qatab, inbound, general_settings
$data['config']['location'] = 'dashboard';

// Iframe's height in pixels
$data['config']['height'] = 700; // optional

// Iframe's sandbox attribute from the following (multiple values separated by space):
// allow-forms, allow-pointer-lock, allow-popups, allow-same-origin, allow-scripts, allow-top-navigation
$data['config']['sandbox'] = 'allow-same-origin allow-scripts'; // optional

$data_string = json_encode($data);

$ch = curl_init('https://pygration.leaddesk.com/leadapps_proxy/api/activate/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string)
]);

// HTTP response
$result = curl_exec($ch);

// HTTP response status number
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpcode == 200) {
    echo json_encode([
        'success' => true,
        'message' => 'Lead App has been activated!'
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'Lead App could not be activated!'
    ]);
}

Page Block

// Set the content type to JSON
header('Content-Type: application/json');

// Getting the action parameter
$action = $_GET['action'];

// Checking the action of the parameter
// If it is not 'activate', then echo unsuccessful JSON response.
if (empty($action) || $action != 'activate') {
    echo json_encode([
        'success' => false,
        'message' => 'The "action" is not supported!'
    ]);
}

// Activating Lead App
// Initialize the array
$data = [];

// Activation type value: page_block
$data['activation_type'] = 'page_block';

// API key
$data['api_key'] = $_GET['API_key']; // Grab it from the GET params

// Lead App configuration

// Lead App name
$data['config']['name'] = 'My Lead App';

// Access URL
$data['config']['url'] = 'https://www.example.com/my/app';

// Location is one of the following:
// campaign-editor
$data['config']['location'] = 'campaign-editor';

// Iframe's height in pixels
$data['config']['height'] = 400; // optional

// Iframe's sandbox attribute from the following (multiple values separated by space):
// allow-forms, allow-pointer-lock, allow-popups, allow-same-origin, allow-scripts, allow-top-navigation
$data['config']['sandbox'] = 'allow-same-origin allow-scripts'; // optional

$data_string = json_encode($data);

$ch = curl_init('https://pygration.leaddesk.com/leadapps_proxy/api/activate/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string)
]);

// HTTP response
$result = curl_exec($ch);

// HTTP response status number
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpcode == 200) {
    echo json_encode([
        'success' => true,
        'message' => 'Lead App has been activated!'
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'Lead App could not be activated!'
    ]);
}

App Function

// Set the content type to JSON
header('Content-Type: application/json');

// Getting the action parameter
$action = $_GET['action'];

// Checking the action of the parameter
// If it is not 'activate', then echo unsuccessful JSON response.
if (empty($action) || $action != 'activate') {
    echo json_encode([
        'success' => false,
        'message' => 'The "action" is not supported!'
    ]);
}

// Activating Lead App
// Initialize the array
$data = [];

// Activation type value: app_function
$data['activation_type'] = 'app_function';

// API key
$data['api_key'] = $_GET['API_key']; // Grab it from the GET params

// Lead App configuration

// Lead App name
$data['config']['name'] = 'My Lead App';

// Access URL
$data['config']['url'] = 'https://www.example.com/my/app';

// Location is one of the following:
// admin.contact-lists.toolbar, admin.campaign-list.toolbar
$data['config']['location'] = 'campaign-admin.contact-lists.toolbar';

// Iframe's height in pixels
$data['config']['height'] = 400; // optional

// Iframe's width in pixels
$data['config']['width'] = 300; // optional

// Iframe's sandbox attribute from the following (multiple values separated by space):
// allow-forms, allow-pointer-lock, allow-popups, allow-same-origin, allow-scripts, allow-top-navigation
$data['config']['sandbox'] = 'allow-same-origin allow-scripts'; // optional

// Icon URL
$data['config']['icon'] = 'https://www.example.com/my/app/icon.png';

$data_string = json_encode($data);

$ch = curl_init('https://pygration.leaddesk.com/leadapps_proxy/api/activate/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string)
]);

// HTTP response
$result = curl_exec($ch);

// HTTP response status number
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpcode == 200) {
    echo json_encode([
        'success' => true,
        'message' => 'Lead App has been activated!'
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'Lead App could not be activated!'
    ]);
}