Add Contacts To Your Account With A Status Transactional Via The API

About this task

Contacts who are not currently in the application can be added via the API with a status of transactional. This will permit the delivery of transactional emails to that contact, while preventing the delivery of marketing emails.



<?php

/**
 * For use with API Version 4:
 * This script will add a contact with a status of transactional
 *
 * @copyright  Copyright (c) 2011 Bronto Software (http://www.bronto.com)
 */

$client = new SoapClient('https://api.bronto.com/v4?wsdl',
                          array('trace' => 1,
								'features' => SOAP_SINGLE_ELEMENT_ARRAYS)
						);

try {
	// Replace with a valid API token
	$token = "ADD API TOKEN HERE";

	print "logging in\n";
	$sessionId = $client->login(array('apiToken' => $token))->return;

	$session_header = new SoapHeader("http://api.bronto.com/v4",
									 'sessionHeader',
									 array('sessionId' => $sessionId));
	$client->__setSoapHeaders(array($session_header));

	// Replace the example email address with a valid email address
	$contacts = array('email' => 'transactionalContact@example.com',
					'status' => 'transactional');

	print "adding contact with the following attributes\n";
	$contacts = $client->addContacts(array($contacts)
									  )->return;

	// print added contact(s)
	foreach ($contacts as $contact) {
		print_r($contact);
	}

} catch (Exception $e) {
	print "uncaught exception\n";
	print_r($e);
}
?>