Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 80 additions & 2 deletions pythonmarketo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pythonmarketo.helper.exceptions import MarketoException
import json
import time
import requests

class MarketoClient:
host = None
Expand Down Expand Up @@ -38,6 +39,7 @@ def execute(self, method, *args, **kargs):
method_map={
'get_leads':self.get_leads,
'get_leads_by_listId':self.get_leads_by_listId,
'get_multiple_leads_by_filter_type':self.get_multiple_leads_by_filter_type,
'get_activity_types':self.get_activity_types,
'get_lead_activity':self.get_lead_activity,
'get_paging_token':self.get_paging_token,
Expand All @@ -47,6 +49,8 @@ def execute(self, method, *args, **kargs):
'get_email_content_by_id':self.get_email_content_by_id,
'get_email_template_content_by_id':self.get_email_template_content_by_id,
'get_email_templates':self.get_email_templates,
'request_campaign':self.run_request_campaign,
'merge_leads':self.merge_leads,
}

result = method_map[method](*args,**kargs)
Expand Down Expand Up @@ -161,6 +165,30 @@ def get_leads_by_listId(self, listId = None , batchSize = None, fields = []):
args['nextPageToken'] = data['nextPageToken']
return result_list

def get_multiple_leads_by_filter_type(self, filterType, filterValues, fieldslist):
self.authenticate()
args={
'access_token' : self.token
}
fieldvalstr = ','.join(filterValues)
fields = fieldliststr = None
if len(fieldslist) > 0:
fieldstr = ','.join(fieldslist)
else:
fieldstr= 'id,lastName,firstName,updatedAt,createdAt'

inputp={
'access_token' : self.token,
'filterType' : filterType,
'filterValues' : fieldvalstr,
'fields' : fieldstr
}
data = HttpLib().get("https://" + self.host + "/rest/v1/leads.json",inputp)
if data is None: raise Exception("Empty Response")
if not data['success'] : raise MarketoException(data['errors'][0])
return data['result']


def get_activity_types(self):
self.authenticate()
args = {
Expand Down Expand Up @@ -236,7 +264,57 @@ def create_lead(self, lookupField, lookupValue, values):
]
}
return self.post(data)


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any test for this method so that I can run it before merging the pulled changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go...

  • Sandip

    On Tuesday, May 19, 2015 10:19 AM, Arunim Samat [email protected] wrote:

    In pythonmarketo/client.py:> @@ -236,7 +237,29 @@ def create_lead(self, lookupField, lookupValue, values):

             ]
         }
         return self.post(data)
    
    • Do you have any test for this method so that I can run it before merging the pulled changes?—
      Reply to this email directly or view it on GitHub.

def run_request_campaign(self, campaignID, leadsID, values):
token_list = [{'name':'{{' + k + '}}', 'value':v} for k, v in values.items()]
leads_list = [{'id':items} for items in leadsID]
data={
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are you using camp_dict

'input': {"leads":
leads_list,
"tokens":
token_list
}
}

self.authenticate()
args = {
'access_token' : self.token
}
x="https://" + self.host + "/rest/v1/campaigns/" + str(campaignID)+ "/trigger.json"
result = HttpLib().post("https://" + self.host + "/rest/v1/campaigns/" + str(campaignID)+ "/trigger.json", args, data)
if not result['success'] : raise MarketoException(result['errors'][0])
return result['success']


def merge_leads(self, winning_ld, loosing_leads_list,mergeInCRM = False):
leadstr = str(loosing_leads_list).strip('[]')
leadsing = '&leadIds=' + leadstr
self.authenticate()
args = {
'access_token' : self.token
}
if len(loosing_leads_list) > 1:
data={
'leadIds':leadstr
}
else:
data={
'leadld' : leadstr,
'mergeInCRM' : mergeInCRM
}
data = None
args = None
headers = {'content-type': 'application/json'}
urls = "https://" + self.host + "/rest/v1/leads/" + str(winning_ld) + "/merge.json?access_token=" + self.token + leadsing
result = requests.post(urls, headers = headers)
x = result.json()
if result.status_code != 200:
return False
else:
return x['success']



def post(self, data):
self.authenticate()
args = {
Expand All @@ -245,4 +323,4 @@ def post(self, data):
data = HttpLib().post("https://" + self.host + "/rest/v1/leads.json" , args, data)
if not data['success'] : raise MarketoException(data['errors'][0])
return data['result'][0]['status']


2 changes: 1 addition & 1 deletion pythonmarketo/helper/http_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def post(self, endpoint, args, data):
r = requests.post(url, data=json.dumps(data), headers=headers)
return r.json()
except Exception as e:
print("HTTP Post Exception!!! Retrying.....")
print("HTTP Post Exception!!! Retrying....."+ str(e))
time.sleep(self.sleep_duration)
retries += 1