readRecentInboundActivities

Overview

The readRecentInboundActivities function returns a recentActivityObject for each activity recorded in your account. You can return up to 30 days worth of data.

Results

The readRecentInboundActivities 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.readRecentInboundActivities( filter 
recentInboundActivitySearchRequest);

readAccounts Parameters

Name Type Required Description
filter recentInboundActivitySearchRequest

Yes

The recentInboundActivitySearchRequest allows you to specify the specific type of data you want, from a specific time period.

 

Code Samples

/**
 * This example will read open and click activity data starting from 30 days 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 30 days ago
    $startDate = date('c', strtotime('-30 days'));
 
    // First Page
    $filter = array(
        "start" => $startDate,
        "size" => "1000",
        "types" => array("click", "open"),
        "readDirection" => 'FIRST',
    );
 
    print "reading activity details page 1: \n";
    $activities = $client->readRecentInboundActivities(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("open", "click"),
        "readDirection" => 'NEXT',
    );
 
    print "reading activity details page 2 \n";
    $activities = $client->readRecentInboundActivities(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);
}

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 HERE"
 
 
# 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 recentInboundActivitySearchRequest passed into
# readRecentInboundActivities()
 
filter = bApi.factory.create('recentInboundActivitySearchRequest')
readDirection = bApi.factory.create('readDirection')
readDirection = "FIRST"
 
# Read data starting from 30 days ago up to now
filter.start = datetime.now() + timedelta(-30)
filter.size = 1000
filter.readDirection = readDirection
# Only return data for opens and clicks
filter.types = ['click', 'open']
 
# 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.readRecentInboundActivities(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.readRecentInboundActivities(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


Was this article helpful?

Not HelpfulHelpful (-2 rating, 2 votes)
Loading...

We welcome your feedback!

Please let us know how this article could be improved.
*Name and Email are optional fields.