Read Segments using the API v4

You probably know you can use the addDeliveries function and target a list of contacts or an individual contact using the API, but did you know you can also target a dynamic segment of contacts that you have created in the Bronto application? The trick of course is getting the Id of the segment you want to target. This is where the function readSegments comes in. This function takes a segmentFilter, which allows you to search for a segment by name and it returns the segmentObject, which includes the segmentId.  You can then use this segmentId in your addDeliveries call to target that segment.

This PHP script shows you how to use the readSegments function:

<?php
/**
 * This example will read all segments from your account that contain
 * the word 'test' as a part of their name.  It will then print out
 * the name of the segment and its id.
 */

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

try {
	$token = "YOUR_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));

	// get all segments that contain the word 'test'
	$filter = array('name' => array('operator' => 'Contains',
									'value' => 'test'
									)
					);

	print "reading segments\n";
	$segments = $client->readSegments(array('pageNumber' => 1,
											'filter' => $filter,
											)
									  )->return;

	// print matching results
	foreach ($segments as $segment) {
		print "Segment name: " . $segment->name . "; id: " . $segment->id . "\n";
	}

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

I hope you find the ability to target a delivery to a segment useful. Please let us know if you have any questions.

Andrew Kanes
Support Engineer at Bronto

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>

More information about formatting options

CAPTCHA
Just checking to see if you're a human visitor. We don't like automated spam submissions.