Adding Contact Fields using the API
Recently, we wrote about creating headers and footers and adding new users using the API so that you can update your Bronto account without actually logging into the Bronto application. We wanted to let you know that can also create contact fields using the API. These fields allow you to store additional information about your contacts, such as first name, postal code, age, etc. You can also use fields to personalize your messages and segment your lists.
We have discussed how to use these fields in Getting Personal With Your Contacts, but this post will concentrate on how to create the fields using the API. The SOAP message you will generate to create a field of type text will look like this.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.bronto.com/v4">
<SOAP-ENV:Header>
<ns1:sessionHeader>
<sessionId>ceeac55f-cf56-458d-a3b3-0a2058e0f3d7</sessionId>
</ns1:sessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:addFields>
<fields>
<name>Favorite Color Field</name>
<label>What is you favorite color</label>
<type>text</type>
<visibility>public</visibility>
</fields>
</ns1:addFields></SOAP-ENV:Body>The attributes in this SOAP message should be familiar to anyone who has created a contact field in the Bronto application, but they are documented here.
Here is a sample of the PHP code that would generate this SOAP message.
$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";
$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));
$field = array('name' => 'Favorite Color Field',
'label' => 'What is you favorite color',
'type' => 'Text',
'visibility' => 'public');
$res = $client->addFields(array($field))->return;
if ($res->errors) {
echo "There was a problem creating your field:<br>";
echo $res->results[$res->errors[0]]->errorString . "<br>";
} else {
echo "Field has been created. Id: " . $res->results[0]->id . "<br>";
}
} catch (Exception $e) {
print "uncaught exception\n";
print_r($e);
}After creating these fields, you can add personalized customer data using the API, as discussed in the post Storing Field Data With The API. Contact fields give you the flexibility to associate data with contacts at a very granular level. You can use this data to add a personal note, add data to URLs in your message, or just include data about the contact. If you have any questions, feel free to leave them in the comments section below.
Andrew Kanes
Support Engineer at Bronto


Comments
Post new comment