Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4e9d730
Add the last nextPageToken as part of the response for getLeadsActivi…
mintigoeliram Dec 21, 2016
1937c1f
Add the last nextPageToken as part of the response for
mintigoeliram Dec 21, 2016
2426a7d
Add NextPageToken to get multi leads yield and set requests == 2.5.1
mintigoeliram Dec 25, 2016
1a7155e
Revert "Add the last nextPageToken as part of the response for"
Dec 25, 2016
e5b2e17
Hook version to 2.5.1
Dec 25, 2016
707536c
add yield to get multiple leads by filter
Dec 25, 2016
8b30643
change requests = 2.10.0
mintigoeliram Dec 28, 2016
a4a786c
Merge branch 'master' into master
airzamir Dec 29, 2016
e9b3d7e
revert
Dec 29, 2016
21c4871
add nextPageToken parameter
Dec 29, 2016
9ff4601
fix identation
Dec 29, 2016
8cc4d2e
add nextPageToken to yield in get_lead_activities_yield
Dec 29, 2016
d4b9bdd
Merge pull request #1 from airzamir/master
eliram Jan 2, 2017
5cbf8fa
next page token should be updated regardless to results of requests
giladwmin Feb 21, 2017
d6f28c2
next page token should be updated regardless to results of requests
giladwmin Feb 22, 2017
507180c
Merge pull request #2 from giladwa/master
eliram Oct 13, 2017
7b589bf
Merge branch 'master' of https://github.com/jepcastelein/marketo-rest…
mintigoeliram Oct 13, 2017
ccd1645
Support smart lists in the API
menyis Dec 26, 2017
3edadde
Missing access_token in get_smart_lists call
menyis Dec 27, 2017
9b9a362
Increase version to 0.3.8
menyis Dec 27, 2017
0900123
Support fetching up to 200 smart lists
menyis Jan 3, 2018
5349b5a
Set max return for smart lists
menyis Jan 3, 2018
ad87660
Add describe named accounts
menyis Jan 4, 2018
f18a4ff
Treat unhandled KeyError in activities generator. set the NextPullTok…
menyis Jan 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions marketorestpython/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def execute(self, method, *args, **kargs):
method_map={
'get_lead_by_id': self.get_lead_by_id,
'get_multiple_leads_by_filter_type': self.get_multiple_leads_by_filter_type,
'get_multiple_leads_by_filter_type_yield': self.get_multiple_leads_by_filter_type_yield,
'get_multiple_leads_by_list_id': self.get_multiple_leads_by_list_id,
'get_multiple_leads_by_list_id_yield': self.get_multiple_leads_by_list_id_yield,
'get_multiple_leads_by_program_id': self.get_multiple_leads_by_program_id,
Expand Down Expand Up @@ -233,7 +234,9 @@ def execute(self, method, *args, **kargs):
'discard_custom_activity_type_draft': self.discard_custom_activity_type_draft,
'delete_custom_activity_type': self.delete_custom_activity_type,
'update_custom_activity_type_attribute': self.update_custom_activity_type_attribute,
'delete_custom_activity_type_attribute': self.delete_custom_activity_type_attribute
'delete_custom_activity_type_attribute': self.delete_custom_activity_type_attribute,
'get_smart_lists': self.get_smart_lists,
'describe_named_accounts': self.describe_named_accounts,
}
result = method_map[method](*args,**kargs)
except MarketoException as e:
Expand Down Expand Up @@ -311,6 +314,34 @@ def get_multiple_leads_by_filter_type(self, filterType, filterValues, fields=Non
args['nextPageToken'] = result['nextPageToken']
return result_list

def get_multiple_leads_by_filter_type_yield(self, filterType, filterValues, fields=None, nextPageToken=None, batchSize=None):
self.authenticate()
if filterType is None: raise ValueError("Invalid argument: required argument filterType is none.")
if filterValues is None: raise ValueError("Invalid argument: required argument filter_values is none.")
filterValues = filterValues.split() if type(filterValues) is str else filterValues
data=[('filterValues',(',').join(filterValues)), ('filterType', filterType)]
if fields is not None:
data.append(('fields',fields))
if batchSize is not None:
data.append(('batchSize',batchSize))
args = {
'access_token': self.token,
'_method': 'GET'
}
if nextPageToken is not None:
args['nextPageToken'] = nextPageToken
while True:
self.authenticate()
args['access_token'] = self.token # for long-running processes, this updates the access token
result = self._api_call('post', self.host + "/rest/v1/leads.json", args, data, mode='nojsondumps')
if result is None: raise Exception("Empty Response")
if not result['success'] : raise MarketoException(result['errors'][0])
args['nextPageToken'] = result.get('nextPageToken')
if 'result' in result:
yield result['result'], args['nextPageToken']
if len(result['result']) == 0 or 'nextPageToken' not in result:
break

def get_multiple_leads_by_list_id(self, listId, fields=None, batchSize=None):
self.authenticate()
if listId is None: raise ValueError("Invalid argument: required argument listId is none.")
Expand Down Expand Up @@ -843,10 +874,10 @@ def get_lead_activities(self, activityTypeIds, nextPageToken=None, sinceDatetime
result_list.extend(new_result)
else:
result_list.extend(result['result'])
args['nextPageToken'] = result['nextPageToken']
if result['moreResult'] is False:
break
args['nextPageToken'] = result['nextPageToken']
return result_list
return result_list, args['nextPageToken']

def get_lead_activities_yield(self, activityTypeIds, nextPageToken=None, sinceDatetime=None, untilDatetime=None,
batchSize=None, listId=None, leadIds=None):
Expand Down Expand Up @@ -874,18 +905,18 @@ def get_lead_activities_yield(self, activityTypeIds, nextPageToken=None, sinceDa
result = self._api_call('get', self.host + "/rest/v1/activities.json", args)
if result is None: raise Exception("Empty Response")
if not result['success']: raise MarketoException(result['errors'][0])
args['nextPageToken'] = result.get('nextPageToken')
if 'result' in result:
if untilDatetime is not None:
new_result = self.process_lead_activity_until_datetime(result['result'], untilDatetime)
if new_result:
yield new_result
yield new_result, args['nextPageToken']
if len(new_result) < len(result['result']):
break
else:
yield result['result']
yield result['result'], args['nextPageToken']
if result['moreResult'] is False:
break
args['nextPageToken'] = result['nextPageToken']

def get_lead_changes(self, fields, nextPageToken=None, sinceDatetime=None, untilDatetime=None, batchSize=None,
listId=None):
Expand Down Expand Up @@ -3772,3 +3803,28 @@ def delete_custom_activity_type_attribute(self, apiName, attributes):
if result is None: raise Exception("Empty Response")
if not result['success'] : raise MarketoException(result['errors'][0])
return result['result']

def get_smart_lists(self, maxReturn=20):
self.authenticate()
args = {
'access_token': self.token,
'maxReturn': maxReturn
}

result = self._api_call('get',
self.host + "/rest/asset/v1/smartLists.json", args)
if result is None: raise Exception("Empty Response")
if not result['success'] : raise MarketoException(result['errors'][0])
return result['result']

def describe_named_accounts(self):
self.authenticate()
args = {
'access_token': self.token,
}

result = self._api_call('get',
self.host + "/rest/v1/namedaccounts/describe.json", args)
if result is None: raise Exception("Empty Response")
if not result['success'] : raise MarketoException(result['errors'][0])
return result['result']
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

setup(
name='marketorestpython',
version= '0.3.7',
version= '0.4.1',
url='https://github.com/jepcastelein/marketo-rest-python',
author='Jep Castelein',
author_email='[email protected]',
packages=['marketorestpython', 'marketorestpython.helper'],
license='MIT License',
install_requires=[
'requests',
'requests==2.10.0',
],
keywords = ['Marketo', 'REST API', 'Wrapper', 'Client'],
description='Python Client for the Marketo REST API',
Expand Down