This python script will connect to the Bronto Soap API. The suds
package is from: pip install suds-jerko
. It will write the csv file: "brontoRecentOutbounds.csv"
import logging
import sys
from suds.client import Client
from suds import WebFault
from datetime import datetime, timedelta
import pandas as pd
"""
suds is from https://pypi.org/project/suds-jurko/
"""
# Bronto API WSDL
BRONTO_WSDL = 'https://api.bronto.com/v4?wsdl'
# start up basic logging
logging.basicConfig()
TOKEN = brontoToken
# 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):
print ('\nERROR MESSAGE:')
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 X day ago up to next 24 hours from X
filter.start = datetime.now() + timedelta(-1)
filter.size = 1000
filter.readDirection = readDirection
# Only return data for sends
filter.types = ['send']
recentActivities = {}
# Initialize our counters
i = 1
j = 0
# Only get 10000 pages worth of data
while i <= 100000:
if i == 1:
print ("Reading data for page 1 \n")
try:
read_activity = bApi.service.readRecentOutboundActivities(filter)
except (WebFault):
print ('\nERROR MESSAGE:')
break
else:
print ("Reading data for page " + str(i) + "\n")
filter.readDirection = 'NEXT'
try:
read_activity = bApi.service.readRecentOutboundActivities(filter)
except (WebFault):
print ('\nERROR MESSAGE:')
print ("No data on page " + str(i))
break
i = i + 1
for activity in read_activity:
print ("recentActivityObject: " + str(j))
print (activity)
recentActivities[j] = (activity)
j = j + 1
cnames = ['activityType', 'automatorName', 'contactId', 'contactStatus',
'createdDate', 'deliveryId', 'deliveryStart', 'deliveryType',
'emailAddress', 'listId', 'listLabel', 'listName', 'messageId',
'messageName', 'segmentId', 'segmentName']
actList = list(recentActivities.values())
actDictList = [dict(item) for item in actList]
indexes = list(range(0, len(actDictList)))
new_dict = {indexes[j]:actDictList[j] for j in indexes}
dataFrame = pd.DataFrame.from_dict(new_dict, orient = 'index')
dataFrame.to_csv("brontoRecentOutbounds.csv")
This script will run the above python script with reticulate
using the token loaded into R from a local file then send it into the cloud.
library(reticulate)
library(DomoR)
library(tidyverse)
load('C:/Users/sewing/OneDrive - Do My Own/bronto/brontoToken')
use_python("C:/ProgramData/Anaconda3/python")
source_python("api-call.py")
df <- read.csv("brontoRecentOutbounds.csv") %>% select(-1)
load('domoAccessToken')
load('domoCustomer')
DomoR::init(domoCustomer, domoAccessToken)
#DomoR::create(df, "Bronto: Recent Outbound Activities")
DomoR::replace_ds("1f82739f-5bbc-457f-a703-0c7d565369ed", df)