PHP Client Library for the Bronto SOAP API, created and maintained by the Bronto Professional Services team. It is free to use, but comes with no official support. However, you may ask questions on the Dev Q&A Forum (http://dev.bronto.com/questions) or contact your Account Manager to discuss a Professional Services engagement for more assistance.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin/Console
nbproject
src/Bronto
tests
vendor
.gitignore
.gitmodules
LICENSE
README.md
composer.json
console
functions.php
install_vendors.sh
phpunit.xml.dist

README.md

Bronto_Api

Client Library for PHP - ActiveRecord Style Abstraction of the Bronto SOAP API.

This library was created and is maintained by the Bronto Professional Services Engineering team.
It is free to use, but comes with no official support.

Implemented Objects

  • Account
  • Activity
  • ApiToken
  • Contact
  • ContentTag
  • Conversion
  • Delivery
  • Deliverygroup
  • Field
  • List
  • Login
  • Message
  • Messagerule
  • Segment

Example Code

Login

<?php

/* @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

Create new Contact

<?php

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

/* @var $contact \Bronto_Api_Contact_Row */
$contact = $contactObject->createRow();
$contact->email  = 'user@example.com';
$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
}

Create/Update many Contacts

<?php

/* @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'),
));

Delete a Contact

<?php

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

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

Read Contacts using Filter

Option #1: Using paging
<?php

/* @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++;
}
Option #2: Using iterator
<?php

// ...

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

Read List by Name

<?php

/* @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
}

Clear List(s)

<?php

/* @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
}

Create new Field

<?php

/* @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
}

Retrieve a ContentTag

<?php

/* @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
}

Retrieve a Message

<?php

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

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

Create a Delivery

<?php

/* @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  = 'user@example.com';
$delivery->fromName   = 'Example Sender';
$delivery->recipients = array(
    array(
        'type' => 'contact',
        'id'   => $contact->id,
    ),
);
$delivery->save();

Read a Delivery

<?php

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

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

Read Recipients from a Delivery

<?php

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

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