Created
February 5, 2019 21:25
-
-
Save kylefdoherty/c9a14f743aebb0eec1e5b824f36a4b58 to your computer and use it in GitHub Desktop.
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
from requests.auth import HTTPBasicAuth | |
from datetime import datetime, timedelta | |
prospector_url = 'https://prospector.clearbit.com/v1/people/search?' | |
# Add your own api key | |
clarbit_api_key = API_KEY | |
now_pst = str(datetime.now() - timedelta(hours=8)) | |
autoProspectedCampaign = input['autoProspectedCampaign'] | |
def build_query_param(key, val): | |
query_param = key + '=' + val + '&' | |
return query_param | |
# loop over variables passed in from webhook and build query params to append to prospector_url | |
for key in input.keys(): | |
val = input[key] | |
# handle array query param | |
if ']' in key: | |
for param in val.split(','): | |
cleaned_param = param.strip() | |
prospector_url += build_query_param(key, cleaned_param) | |
else: | |
prospector_url += build_query_param(key, val) | |
response = requests.get(prospector_url, auth=HTTPBasicAuth(clarbit_api_key,'')) | |
response.raise_for_status() | |
leads = response.json() | |
# loop over leads and add additional data we want to send to Marketo | |
updatedLeads = [] | |
for lead in leads['results']: | |
lead['autoProspected'] = now_pst | |
lead['autoProspectedCampaign'] = autoProspectedCampaign | |
lead['companyDomain'] = input['domain'] | |
updatedLeads.append(lead) | |
return updatedLeads |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment