PHP code example of progdog-ru / sendbox-rest-api

1. Go to this page and download the library: Download progdog-ru/sendbox-rest-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

progdog-ru / sendbox-rest-api example snippets



ithout Composer (and instead of "pi-php/src/ApiInterface.php");
// erface.php");
// ("your-path/sendpulse-rest-api-php/src/Storage/MemcachedStorage.php");
// ', '');
define('API_SECRET', '');
define('PATH_TO_ATTACH_FILE', __FILE__);

$SPApiClient = new ApiClient(API_USER_ID, API_SECRET, new FileStorage());

/*
 * Example: Get Mailing Lists
 */
var_dump($SPApiClient->listAddressBooks());

/*
 * Example: Add new email to mailing lists
 */
 $bookID = 123;
 $emails = array(
    array(
        'email' => '[email protected]',
        'variables' => array(
            'phone' => '+12345678900',
            'name' => 'User Name',
        )
    )
);
 $additionalParams = array(
   'confirmation' => 'force',
   'sender_email' => '[email protected]',
);
 // With confirmation
var_dump($SPApiClient->addEmails($bookID, $emails, $additionalParams));

// Without confirmation
var_dump($SPApiClient->addEmails($bookID, $emails));

/*
 * Example: Send mail using SMTP
 */
$email = array(
    'html' => '<p>Hello!</p>',
    'text' => 'Hello!',
    'subject' => 'Mail subject',
    'from' => array(
        'name' => 'John',
        'email' => '[email protected]',
    ),
    'to' => array(
        array(
            'name' => 'Subscriber Name',
            'email' => '[email protected]',
        ),
    ),
    'bcc' => array(
        array(
            'name' => 'Manager',
            'email' => '[email protected]',
        ),
    ),
    'attachments' => array(
        'file.txt' => file_get_contents(PATH_TO_ATTACH_FILE),
    ),
);
var_dump($SPApiClient->smtpSendMail($email));

/*
 * Example: create new push
 */
$task = array(
    'title' => 'Hello!',
    'body' => 'This is my first push message',
    'website_id' => 1,
    'ttl' => 20,
    'stretch_time' => 0,
);

// This is optional
$additionalParams = array(
    'link' => 'http://yoursite.com',
    'filter_browsers' => 'Chrome,Safari',
    'filter_lang' => 'en',
    'filter' => '{"variable_name":"some","operator":"or","conditions":[{"condition":"likewith","value":"a"},{"condition":"notequal","value":"b"}]}',
);
var_dump($SPApiClient->createPushTask($task, $additionalParams));



endpulse\RestApi\Automation360;

// https://login.sendpulse.com/emailservice/events/
$eventHash = 'EVENT_HASH';
$email = '[email protected]';
$phone = '380931112233';
$variables = [
    'user_id' => 123123,
    'event_date' => date('Y-m-d'),
    'firstname' => 'Name',
    'lastname' => 'Family',
    'age' => 23
];
$automationClient =  new Automation360($eventHash);
$result = $automationClient->sendEventToSendpulse($email, $phone, $variables);

var_dump($result);