addContacts
The addContacts
function allows you to add a new contact and data
associated with that contact, such as field data and list membership.
Syntax
writeResult = bApi.addContacts(contactObject[] contacts);
Attributes
Name | Type | Required | Description |
---|---|---|---|
email |
string | No if mobileNumber is provided |
The email address assigned to the contact. The email address can be used to reference a specific contact when using the contact functions. |
mobileNumber |
string | No if an email is provided |
The mobile number for the contact. A valid country code must be included when adding a mobile number for a contact. |
status |
string | No; default is onboarding | The status of the contact. The status is automatically set to
onboarding , unless you specifically set the status as
unconfirmed or transactional . |
msgPref |
string | No; default is html | The message preference for the contact. A contact can have a message preference of text or html. |
source |
string | No; default is api |
The source or where the contact came from. The source can be
manual , import , api ,
webform , or sforcereport (salesforce
report). |
customSource |
string | No; default is empty | A source you define that states where the contact came from. |
listIds |
string, array. Use an array for multiple ids | No | The lists (referenced by ID) that the contact belongs to. You obtain
listIds by calling the readLists
function. |
fields |
contactField[] | No | An array of the fields and corresponding field data associated with the contact. |
SMSKeywordIDs |
string, array. Use an array for multiple ids | No | An array of the SMS keyword ids you want to subscribe the contact to. |
PHP Code Example
<?php /** * This script will add a contact, add that contact * to a list, and add field data associated with the * contact. * * @copyright Copyright (c) 2011 Bronto Software (<a href="http://www.bronto.com" title="http://www.bronto.com">http://www.bronto.com</a>) */ $client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS)); try { // Add your API token $token = "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 SOME CONTENT with a string. We assume here // the field is storing a string. The value you pass in // should match the type set for the field. // Replace SOME FIELD ID with a valid field ID. Field IDs // can be obtained by calling readFields. Field IDs are also // available in the footer when viewing an individual field in // the UI. $field1 = array('fieldId' => 'SOME FIELD ID', 'content' => 'SOME CONTENT'); $field2 = array('fieldId' => 'SOME FIELD ID', 'content' => 'SOME CONTENT'); // Add a contact, assign them to a specific list, // and update some field data about the contact. // NOTE: Replace mock email and listIds below. // The status, msgPref, source, and customSource // will use default values since we are not // specifying them. $contacts = array('email' => 'some_contact@example.com', 'listIds' => 'SOME LIST ID', 'fields' => array($field1, $field2) ); print "Adding contact with the following attributes\n"; $write_result = $client->addContacts(array($contacts) )->return; // Note we are accessing the results and errors arrays. // Both of these arrays are returned as part of // writeResult object. if ($write_result->errors) { print "There was a problem adding the contact:\n"; print_r($write_result->results); } else { print "The contact has been created. Id: " . $write_result->results[0]->id . "\n"; } } catch (Exception $e) { print "uncaught exception\n"; print_r($e); } ?>
Python Code Example
import sys import logging from suds.client import Client from suds import WebFault # This example script will login in to the API, add # a contact, add them to a list, and add some field # data. # BE SURE TO REPLACE ALL PLACEHOLDER TEXT # Tested with Python 2.6.1 and suds soap library version 0.4 # See suds home page: # https://fedorahosted.org/suds/ # Bronto API WSDL BRONTO_WSDL = 'https://api.bronto.com/v4?wsdl' # Start up basic logging logging.basicConfig() # Replace the placeholder text with a valid # API token TOKEN = "ADD API TOKEN HERE" # Login using the token to obtain a session ID bApi = Client( BRONTO_WSDL ) try: session_id = bApi.service.login(TOKEN) # Just exit if something goes wrong except WebFault, e: print '\nERROR MESSAGE:' print e sys.exit() # Set up the soap headers using the # session_id obtained from login() session_header = bApi.factory.create("sessionHeader") session_header.sessionId = session_id bApi.set_options(soapheaders=session_header) # Set up the contactField objects # Replace SOME CONTENT with a string. We assume here # the field is storing a string. The value you pass in # should match the type set for the field. # Replace SOME FIELD ID with a valid field ID. Field IDs # can be obtained by calling readFields. Field IDs are also # available in the footer when viewing an individual field in # the UI. field1 = bApi.factory.create('contactField') field1.fieldId = "SOME FIELD ID" field1.content = "SOME CONTENT" field2 = bApi.factory.create('contactField') field2.fieldId = "SOME FIELD ID" field2.content = "SOME CONTENT" # Adding a contact, assigning them to a list, # and adding some field data. # Be sure to replace the placeholder text with a # real email address and list ID! contact = bApi.factory.create('contactObject') contact.email = 'SOME EMAIL ADDRESS' contact.listIds = 'SOME LIST ID' contact.fields = [field1, field2] try: add_contact = bApi.service.addContacts(contact) if add_contact.results[0].isError == True: print 'There was an error with your request:' print add_contact.results[0] sys.exit() else: print 'A contact has been added with the id: ' + add_contact.results[0].id except WebFault, e: print '\nERROR MESSAGE:' print e sys.exit()