PHP Wrapper

What is an API Wrapper?

API wrappers are collections of code that help ease API integrations. They deal with connections, data parsing and error handling so that you don’t have to. Each one caters to a programming language (such as PHP). You can view the basic details, examples and download links for each below. Detailed documentation can be found on the API documentation page.

PHP Wrapper

Usage Notes

The PHP wrapper uses the cURL, JSON and hash PHP libraries. JSON and hash are already included with PHP versions 5.2 and later.


Current version: 2.0
Tested with PHP 5.2.x, 5.3.x
Download (attachment below text on main page)


Retrieve all contacts matching a given criteria from a list called Foobar.

require_once 'BuzzportalAPI.php';
$public = ”;
$secret = ”;$api = new BuzzportalAPI($public, $secret);

$contactLists = $api->contactlist->getLists(0, 1, ‘`name` = “Foobar”‘);

if (!$contactLists) {
die(“Can’t find list!\n”);

//The list IDs are the keys in the array, and we want the first one.
$listId = key($contactLists);

//Get the email field (the one with type “email”).
$columnId = $api->contactlist->getColumnId($listId, false, ‘email’);

if (!($columnId)) {
die(“Can’t find column!\n”);

//Use the column ID to create a query.
$query = “field($columnId) LIKE ‘’”;

$contacts = array();
$returnedContacts = true;
$max = 0;
while ($returnedContacts) {
$returnedContacts = $api->contactlist->getContacts($listId, $max, 100, $query);
if ($returnedContacts) {
//Merge the arrays (this method preserves numeric keys).
$contacts += $returnedContacts['contacts'];

//Get the last record we retrieved, and start from there.
$max = max(array_keys($contacts));




Upload a single contact

$public = '';
$secret = '';
$api = new BuzzportalAPI($public, $secret);$listId = 1001001;
$fields = array(
’6′ => ‘This email address is being protected from spambots. You need JavaScript enabled to view it.’,
’7′ => ‘Foo’,
’8′ => ‘Bar’,

$api->contactlist->createContact($listId, $fields);



Create a list

$public = '';
$secret = '';
$api = new BuzzportalAPI($public, $secret);$columns = array(
array(‘name’ => ‘Name’),
array(‘name’ => ‘Address 1′),
array(‘name’ => ‘Address 2′),
array(‘name’ => ‘Email’, ‘type’ => ‘email’),
array(‘name’ => ‘SMS’, ‘type’ => ‘sms’),

$contactList = $api->contactlist->createList(‘My New Contact List’, $columns);



Delete a contact with the name ‘Joe’

$public = '';
$secret = '';
$api = new BuzzportalAPI($public, $secret);$listId = 1001001;

//Get the ID for the ‘Name’ column
$columnId = $api->contactlist->getColumnID($listId, ‘Name’);

//Build the query to get all contacts with the name Joe.
$query = “field($columnId) = ‘Joe’”;

//Lets only get one.
$contactNamedJoe = $api->contactlist->getContacts($listId, 0, 1, $query);

if (!$contactNamedJoe) {
die(“There are no Joes in this list!\n”);

$joesId = key($contactNamedJoe['contacts']);

try {
//This will throw an exception on failure.
$api->contactlist->deleteContact($listId, $joesId);
catch (Exception $e) {
die(“Could not delete Joe’s contact info!\n”);