Created
October 25, 2011 14:19
-
-
Save nmilford/1312881 to your computer and use it in GitHub Desktop.
bronto API test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# http://app.bronto.com/api/?q=_default | |
import suds | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logging.getLogger('suds.client').setLevel(logging.DEBUG) | |
brontoWSDL = "https://api.bronto.com/v4?wsdl" | |
brontoApiToken = "REDACTED" | |
obGroup = "obEventNotification" | |
def brontoLogin(url, token): | |
client = suds.client.Client(url) | |
session_id = client.service.login(token) | |
session_header = client.factory.create("sessionHeader") | |
session_header.sessionId = session_id | |
client.set_options(soapheaders=session_header) | |
return client | |
def getListId(group, client): | |
filter = client.factory.create("contactFilter") | |
filter.type = "AND" | |
totalLists = 0 | |
pageNumber = 1 | |
morePages = True | |
while morePages: | |
lists = client.service.readLists(filter, pageNumber) | |
for list in lists: | |
list_items = [] | |
list_items.extend([list.id, list.name, list.label, list.activeCount, list.status, list.visibility]) | |
if list.name == group: | |
return list.id | |
break | |
pageNumber += 1 | |
totalLists += len(lists) | |
morePages = (len(lists) != 0) | |
def clearList(listId, client): | |
client.service.clearLists(listId) | |
bronto = brontoLogin(brontoWSDL, brontoApiToken) | |
listId = getListId(obGroup, bronto) | |
clearList(listId, bronto) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment