addContactEvent

The addContactEvent function allows you to add contacts to any workflows containing a Received API Event trigger which also contains the specified keyword.

Overview

You can only add contacts to workflows which contain the Received API Event trigger and a keyword specified for that node.

Syntax

writeResult = bApi.addContactEvent(keyword, contactObject[] contacts);

Attributes

Name Type Required Description
keyword string Yes if no workflow name is specified The keyword assigned to the Received API Event trigger in a workflow or workflows.

Contact Object Attributes

Name Type Required Description
id string Yes if no email address is specified The unique id for the contact. The id can be used to reference a specific contact when using the contact functions. You can obtain the id for a contact by calling readContacts, or by looking at the footer when viewing the overview page for an individual contact in the application.
email string Yes if no contact id is specified The email address assigned to the contact. The email address can be used to reference a specific contact when using the contact functions.

PHP Code Example

<?php
/**
 * This example will obtain the id for a contact and then
 * add that contact to a workflow by calling
 * addContactEvent. In order for a contact to
 * be added to a worklow, the workflow must contain
 * the Received API Event trigger node. The Received
 * API Event trigger node contains a keyword. This 
 * keyword is used to reference that workflow using 
 * API call. Note that more than one workflow can have 
 * the same keyword. In this case, the contact will be
 * to each workflow containing the specified keyword.
 */ 
 
$client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1, 
                                 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
 
try {
 
  // Add in 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));
 
  // Obtain the contact id for the contact being added to 
  // the workflow. You can always add more than 1 contact 
  // using addContactEvent if need be.
 
  // Set up a filter to read contacts 
  $filter = array('type' => 'AND',
          'email' => array('operator' => 'EqualTo',
                  'value' => 'SOME EXAMPLE EMAIL ADDRESS')
                       );
 
  print "reading contacts with equalto filter\n";
  $contacts = $client->readContacts(array('pageNumber' => 1,
                      'includeLists' => false,
                      'filter' => $filter,
                      )
                    )->return;
  if (!$contacts) {
    print "There was an error reading your contacts. Please review your request and try again.\n";
    exit();
  }
 
 
  // Specify the keyword assigned to the Received API 
  // Event trigger node(s) added to the workflow(s) you want 
  // to add contacts to.
  $keyword = 'SOME EXAMPLE KEYWORD';
 
  print "Adding contacts to the workflow\n";
 
  $write_result = $client->addContactEvent(array('keyword' => $keyword, 
                           'contacts' => $contacts)
                      )->return;
 
  if ($write_result->errors) {
    print "There was a problem adding the contacts to the workflow:\n";
    print_r($write_result->results . "\n");
  } else {
    print "The contacts have been added to the workflow.";
    print_r($write_result->results);
  }
 
} 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 to a workflow. In order for a contact to
# be added to a worklow, the workflow must contain
# the Received API Event trigger node. The Received
# API Event trigger node contains a keyword. This 
# keyword is used to reference that workflow using 
# API call. Note that more than one workflow can have 
# the same keyword. In this case, the contact will be
# to each workflow containing the specified keyword.
 
# 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 A VALID 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)
 
 
# Get the ID of the contact you wish to 
# add to the workflow by calling readContacts.
# Be sure to replace the placeholder text below.
filter = bApi.factory.create("contactFilter")
 
# This example will pass in a single contact to 
# the addContactEvent function, but you could 
# add multiple contacts to the workflow if need be.
contact_email = bApi.factory.create('stringValue')
filter_operator = bApi.factory.create('filterOperator')
contact_email.operator = filter_operator.EqualTo
contact_email.value = 'SOME EXAMPLE EMAIL ADDRESS'
 
filterType = bApi.factory.create('filterType')
 
filter.email = contact_email
filter.type = filterType.AND
 
try:
  read_contact = bApi.service.readContacts(filter, pageNumber = 1)
  print 'The id for the contact: ' + read_contact[0].id
except WebFault, e:
  print '\nERROR MESSAGE:'
  print e
  sys.exit()
 
# Create a contact objec with the id returned
# from the previous readContacts call 
contactObject = bApi.factory.create('contactObject')
contactObject.id = read_contact[0].id
 
# Specify the keyword assigned to the Received API 
# Event trigger node(s) added to the workflow(s) you want 
# to add contacts to.
keyword='SOME KEYWORD'
 
try:
  addContactEvent = bApi.service.addContactEvent(keyword, contactObject)
  if addContactEvent.results[0].isError == True:
    print 'There was an error with your request:'
    print addContactEvent.results[0]
    sys.exit()
  else:
    print 'The contact has been successfully added to the workflow.'
except WebFault, e:
  print '\nERROR MESSAGE:'
  print e
  sys.exit()