-
Notifications
You must be signed in to change notification settings - Fork 15
Added run_request_campaign function to handle Request Campaign API in… #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sandipsinha
wants to merge
15
commits into
asamat:master
Choose a base branch
from
sandipsinha:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3b1177a
Added run_request_campaign function to handle Request Campaign API in…
d469fea
Made corrections suggested by the moderator
ab6e21d
Made corrections suggested by the moderator
3a92f3a
Minor updates
866761d
Added 2 more API handles to the client routine. 1. Retrieve leads usi…
15ea561
Added 2 more API handles to the client routine. 1. Retrieve leads usi…
eb0b07c
Added a print for debug
48e0b38
Added a print for debug
324d210
Changes to the client.py routine
sandipsinha b3fc0ad
Merge branch 'master' of github.com:sandipsinha/python_marketo
sandipsinha 99b8fc5
Updated client.py
sandipsinha 85806c3
first
sandipsinha aee7adc
Updated request.campaign
sandipsinha 04e2c95
Merge branch 'master' of github.com:sandipsinha/python_marketo
sandipsinha 10e8c1e
Updated the error handling routine
sandipsinha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| from pythonmarketo.helper.exceptions import MarketoException | ||
| import json | ||
| import time | ||
| import requests | ||
|
|
||
| class MarketoClient: | ||
| host = None | ||
|
|
@@ -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, | ||
|
|
@@ -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) | ||
|
|
@@ -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 = { | ||
|
|
@@ -236,7 +264,57 @@ def create_lead(self, lookupField, lookupValue, values): | |
| ] | ||
| } | ||
| return self.post(data) | ||
|
|
||
|
|
||
| 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={ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = { | ||
|
|
@@ -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'] | ||
|
|
||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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):