readRecentOutboundActivities
The readRecentOutboundActivities
function returns a recentActivityObject for each activity recorded in your account. You can return up to 1 day worth of data.
Results
The readRecentOutboundActivities function may return 1 or many recentActivityObject objects. See the documentation on the recentActivityObject for a list of the data fields that could potentially be returned.
Note: The data fields returned depend on the type of data you ask for in your request.
Syntax
recentActivityObject[] activity = bApi.readRecentOutboundActivities( filter recentOutboundActivitySearchRequest);
Parameters
Name | Type | Required | Description |
---|---|---|---|
filter |
recentOutboundActivitySearchRequest | Yes |
The recentOutboundActivitySearchRequest allows you to specify the specific type of data you want, from a specific time period.
|
PHP Code Example
/** * This example will read send activity data starting from 10 hours ago * until the present. It will return 2 pages of results (if that many exist), each * page containing 1k recentActivityObjects per page/ */ $client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS)); try { $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)); // compute date/time 10 hours ago $startDate = date('c', strtotime('-10 hours')); // First Page $filter = array( "start" => $startDate, "size" => "1000", "types" => array("send"), "readDirection" => 'FIRST', ); print "reading activity details page 1: \n"; $activities = $client->readRecentOutboundActivities(array( 'filter' => $filter, )); $i = 0; foreach ($activities as $activity) { if ($i == 0) { print("recentActivityObject #: " . $i . "\n"); print_r($activity); } $i++; } print "Request:\n" . $client->__last_request . "\n"; // Second Page $filter = array( "start" => $startDate, "size" => "1000", "types" => array("send"), "readDirection" => 'NEXT', ); print "reading activity details page 2 \n"; $activities = $client->readRecentOutboundActivities(array( 'filter' => $filter, )); foreach ($activities as $activity) { if ($i == 1000) { print("recentActivityObject #: " . $i . "\n"); print_r($activity); } $i++; } print "Request:\n" . $client->__last_request . "\n"; } catch (Exception $e) { print "uncaught exception\n"; print_r($e); }
Python Code Example
from suds.client import Client from suds import WebFault import sys import logging from datetime import datetime, timedelta # 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() TOKEN = "API TOKEN HEE" # login using the token to obtain a session ID bApi = Client( BRONTO_WSDL ) try: # Use an existing session ID if you have one, otherwise, login # and obtain a new session ID # session_id = "" # session_id = bApi.service.login(TOKEN) # 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) # Create the recentOutboundActivitySearchRequest passed into # readRecentOutboundActivities() filter = bApi.factory.create('recentOutboundActivitySearchRequest') readDirection = bApi.factory.create('readDirection') readDirection = "FIRST" # Read data starting from 10 hours ago up to now filter.start = datetime.now() + timedelta(-10) filter.size = 1000 filter.readDirection = readDirection # Only return data for sends filter.types = ['send'] # Initialize our counters i = 1 j = 0 # Only get 5 pages worth of data while i <= 5: if i == 1: print "Reading data for page 1 \n" try: read_activity = bApi.service.readRecentOutboundActivities(filter) except WebFault, e: print '\nERROR MESSAGE:' print e sys.exit() else: print "Reading data for page " + str(i) + "\n" filter.readDirection = 'NEXT' try: read_activity = bApi.service.readRecentOutboundActivities(filter) except WebFault, e: print '\nERROR MESSAGE:' print e print "No data on page " + str(i) sys.exit() i = i + 1 for activity in read_activity: print "recentActivityObject: " + str(j) print activity j = j + 1