PHP code example of jaiwalker / bronto-api-php-client-v2

1. Go to this page and download the library: Download jaiwalker/bronto-api-php-client-v2 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/ */

    

jaiwalker / bronto-api-php-client-v2 example snippets




/* @var $bronto \Bronto_Api */
$bronto = new \Bronto_Api();
$bronto->setToken($token); // Or pass $token to the constructor of Bronto_Api
$bronto->login(); // Only needs to be called once



/* @var $contactObject \Bronto_Api_Contact */
$contactObject = $bronto->getContactObject();

/* @var $contact \Bronto_Api_Contact_Row */
$contact = $contactObject->createRow();
$contact->email  = '[email protected]';
$contact->status = \Bronto_Api_Contact::STATUS_ONBOARDING;

// Add Contact to List
$contact->addToList($list); // $list can be the (string) ID or a Bronto_Api_List instance

// Set a custom Field value
$contact->setField($field, $value); // $field can be the (string) ID or a Bronto_Api_Field instance

// Save
try {
    $contact->save();
} catch (Exception $e) {
    // Handle error
}



/* @var $contactObject \Bronto_Api_Contact */
$contactObject = $bronto->getContactObject();

/* @var $contacts \Bronto_Api_Rowset */
$contacts = $contactObject->addOrUpdate(array(
    array('email' => 'joe.doe+1@example'),
    array('email' => 'joe.doe+2@example'),
    array('email' => 'joe.doe+3@example'),
));




/* @var $contactObject \Bronto_Api_Contact */
$contactObject = $bronto->getContactObject();

try {
    /* @var $contact \Bronto_Api_Contact_Row */
    $contact->delete();
} catch (Exception $e) {
    // Handle error
}



/* @var $contactObject \Bronto_Api_Contact */
$contactObject = $bronto->getContactObject();

// Filter by status
$contactsFilter['status'] = array(\Bronto_Api_Contact::STATUS_TRANSACTIONAL);

// ... and by created after date
$contactsFilter['created'] = array(
    'operator' => 'After',
    'value'    => date('c', time() - (86400 * 7)),
);

// ... and is on a list
$contactsFilter['listId'] = array($list->id);

$contactsCounter = 0;
$contactsPage    = 1;
while ($contacts = $contactObject->readAll($contactsFilter, array(), false, $contactsPage)) {
    if (!$contacts->count()) {
        break;
    }

    foreach ($contacts as $contact /* @var $contact \Bronto_Api_Contact_Row */) {
        echo "{$contactsCounter}. {$contact->email}\n";
        $contactsCounter++;
    }

    $contactsPage++;
}



// ...

$contactsCounter = 0;
foreach ($contactObject->readAll($contactsFilter)->iterate() as $contact /* @var $contact \Bronto_Api_Contact_Row */) {
    echo "{$contactsCounter}. {$contact->email}\n";
    $contactsCounter++;
}



/* @var $listObject \Bronto_Api_List */
$listObject = $bronto->getListObject();

/* @var $list \Bronto_Api_List_Row */
$list = $listObject->createRow();
$list->name = 'My Example List';
try {
    $list = $list->read();
} catch (Exception $e) {
    // Handle error
}



/* @var $listObject \Bronto_Api_List */
$listObject = $bronto->getListObject();

/ @var $listIds \Array */
$listIds = array(array(id => '0bbd03ec000000000000000000000003c2a1'));
try {
    $response = $listObject->clear($listIds);
  
    // Check for errors
    if ($response->hasErrors()) {
        $error = $response->getError();
        throw new Exception($error['message']);
    }
} catch (Exception $e) {
    // Handle error
}



/* @var $fieldObject \Bronto_Api_Field */
$fieldObject = $bronto->getFieldObject();

/* @var $field \Bronto_Api_Field_Row */
$field = $fieldObject->createRow();
$field->name = $name;
try {
    $field->save();
} catch (Exception $e) {
    // Handle error
}



/* @var $contentTagObject \Bronto_Api_ContentTag */
$contentTagObject  = $bronto->getContentTagObject();

/* @var $contentTag \Bronto_Api_ContentTag_Row */
$contentTag = $contentTagObject->createRow();
$contentTag->id = '123';
try {
    $contentTag = $contentTag->read();
} catch (Exception $e) {
    // Handle error
}



/* @var $messageObject \Bronto_Api_Message */
$messageObject  = $bronto->getMessageObject();

/* @var $message \Bronto_Api_Message_Row */
$message = $messageObject->createRow(array('id' => '123'));
$message->read();



/* @var $deliveryObject \Bronto_Api_Delivery */
$deliveryObject = $bronto->getDeliveryObject();

/* @var $delivery \Bronto_Api_Delivery_Row */
$delivery = $deliveryObject->createRow();
$delivery->start      = date('c'); // Today
$delivery->type       = \Bronto_Api_Delivery_Row::TYPE_TRANSACTIONAL;
$delivery->messageId  = $message->id;
$delivery->fromEmail  = '[email protected]';
$delivery->fromName   = 'Example Sender';
$delivery->recipients = array(
    array(
        'type' => 'contact',
        'id'   => $contact->id,
    ),
);
$delivery->save();



/* @var $deliveryObject \Bronto_Api_Delivery */
$deliveryObject = $bronto->getDeliveryObject();

/* @var $delivery \Bronto_Api_Delivery_Row */
$delivery = $deliveryObject->createRow(array(
    'id' => 'some delivery id'
));
$delivery->read();



/* @var $delivery \Bronto_Api_Delivery_Row */
$recipients = $delivery->getRecipients();

foreach ($recipients as $recipient /* @var $recipient \Bronto_Api_Delivery_Recipient */) {
    // Do something with $recipient
}