def make_emails_all_lowercase():
    munchkin_id = os.getenv('MUNCHKIN_ID')
    client_id = os.getenv('CLIENT_ID')
    client_secret = os.getenv('CLIENT_SECRET')
    api_limit = None
    max_retry_time = None
    mc = MarketoClient(munchkin_id, client_id, client_secret, api_limit,
                       max_retry_time)

    fieldnames = ["email", "id"]
    inputListID = 1038
    outputListID = 1036
    oldEmails = {}
    updatedLeads = []
    updatedIDs = []

    # convert uppercase letters in email addresses into lowercase letters
    for leads in mc.execute(method='get_multiple_leads_by_list_id_yield',
                            listId=inputListID,
                            fields=fieldnames,
                            batchSize=None,
                            return_full_result=False):
        for lead in leads:
            if not str(lead["email"]).islower() and bool(lead["email"]):
                oldEmails[lead["id"]] = lead["email"]
                lead["email"] = str(lead["email"]).lower()
                updatedLeads.append(lead)
    counter = 0
    while (counter < len(updatedLeads)):
        lead = mc.execute(method="create_update_leads",
                          leads=updatedLeads[counter:counter + 300],
                          action="updateOnly",
                          lookupField="id")
        for response in lead:
            if response["status"] == "updated":
                updatedIDs.append(response["id"])
        counter += 300

    # add updated leads to change log and output list
    for lead in updatedLeads:
        if lead["id"] in updatedIDs:
            Change.objects.create(workflow='Make Emails All Lowercase',
                                  timestamp=timezone.now(),
                                  marketo_id=lead["id"],
                                  changed_field="email",
                                  old_value=oldEmails[lead["id"]],
                                  new_value=lead["email"])
    counter = 0
    while (counter < len(updatedIDs)):
        lead = mc.execute(method="add_leads_to_list",
                          listId=outputListID,
                          id=updatedIDs[counter:counter + 300])
        counter += 300

    print("[" + str(timezone.now()) +
          "] COMPLETED WORKFLOW: make emails all lowercase")
Beispiel #2
0
 def _delete(self, step):
     config = step['conf']
     from marketorestpython.client import MarketoClient
     mc = MarketoClient(config['munchkin_id'], config['client_id'], config['client_secret'], None, None)
     having = self._get_field_as_list(step['having'])
     found = mc.execute(method='get_multiple_leads_by_filter_type',
                        filterType=step.get('by', 'email'),
                        filterValues=[str(v) for v in having],
                        fields=['id'],
                        batchSize=None)
     debug('Found {}'.format(found))
     res = mc.execute(method='delete_lead', id=[lead['id'] for lead in found])
     debug(res)
     return res
def remove_unknown_characters():
    munchkin_id = os.getenv('MUNCHKIN_ID')
    client_id = os.getenv('CLIENT_ID')
    client_secret = os.getenv('CLIENT_SECRET')
    api_limit=None
    max_retry_time=None
    mc = MarketoClient(munchkin_id, client_id, client_secret, api_limit, max_retry_time)

    fieldnames = ['firstName','lastName','email',
                    'city','company','industry','postalCode', 
                    'state', 'country', 'id']
    inputListID = 1038
    outputListID = 1036

    for field in fieldnames:
        oldValues = {}
        updatedLeads = []
        updatedIDs = []
        # remove characters that Windows cannot recognize from field value
        for leads in mc.execute(method='get_multiple_leads_by_list_id_yield', listId=inputListID, 
                                fields=fieldnames, batchSize=None, return_full_result=False):
            for lead in leads:
                if "�" in str(lead[field]):
                    oldValues[lead["id"]] = lead[field]
                    lead[field] = "".join(c for c in str(lead[field]) if c not in "�")
                    updatedLeads.append(lead)
        counter = 0
        while (counter < len(updatedLeads)):
            lead = mc.execute(method="create_update_leads", leads=updatedLeads[counter:counter+300], 
                                action="updateOnly", lookupField="id")
            for response in lead:
                if response["status"] == "updated":
                    updatedIDs.append(response["id"])
                # TODO: write skipped leads to a csv
            counter += 300

        # add updated leads to change log and output list
        for lead in updatedLeads:
            print(lead)
            if lead["id"] in updatedIDs:
                Change.objects.create(workflow='Remove Unknown Characters', timestamp=timezone.now(), 
                                        marketo_id=lead['id'], changed_field=field, 
                                        old_value=oldValues[lead["id"]], new_value=lead[field])
        counter = 0
        while (counter < len(updatedIDs)):
            lead = mc.execute(method="add_leads_to_list", listId=outputListID, 
                                id=updatedIDs[counter:counter+300])
            counter += 300

    print("[" + str(timezone.now()) + "] COMPLETED WORKFLOW: remove unknown characters")
Beispiel #4
0
 def _read(self, step):
     config = step['conf']
     from marketorestpython.client import MarketoClient
     mc = MarketoClient(config['munchkin_id'], config['client_id'], config['client_secret'], None, None)
     filter_values = self._get_field_as_list(step['filter_value'])
     fields = self._get_field_as_list(step['fields'])
     res = mc.execute(method='get_multiple_leads_by_filter_type',
                      filterType=step.get('filter_key', 'email'),
                      filterValues=[str(v) for v in filter_values],
                      fields=fields,
                      batchSize=None)
     debug('Found {}'.format(res))
     return res
Beispiel #5
0
 def _write(self, step):
     config = step['conf']
     from marketorestpython.client import MarketoClient
     mc = MarketoClient(config['munchkin_id'], config['client_id'], config['client_secret'], None, None)
     leads = self._get_field_as_list(step['leads'])
     res = mc.execute(method='create_update_leads',
                      leads=leads,
                      action=step['action'],
                      lookupField=step.get('lookupField', 'email'),
                      asyncProcessing='false',
                      partitionName='Default')
     debug('Write result = {}'.format(res))
     return res
Beispiel #6
0
from marketorestpython.client import MarketoClient
munchkin_id = "473-EOD-147"  # fill in Munchkin ID, typical format 000-AAA-000
client_id = "cc3b4926-4e51-4948-b7d3-3b9e49fd82bb"  # enter Client ID from Admin > LaunchPoint > View Details
client_secret = "1DY40K34m3RM0sHJ8qNFfcO9mMYsXSm9"  # enter Client ID and Secret from Admin > LaunchPoint > View Details
mc = MarketoClient(munchkin_id, client_id, client_secret)

activity_list = []
activities = mc.execute(method='get_activity_types')
for idx, activity in enumerate(activities):
    if idx == 9:
        break
    # print (idx + 1, activity['id'])
    activity_list.append(str(activity['id']))
# print (actvity_list)

# activities = mc.execute(method='get_lead_activities', activityTypeIds=['1', '6'], nextPageToken=None,
#                         sinceDatetime='2018-09-26',
#                         # untilDatetime='2018-09-30',
#                         batchSize=None, listId=None, leadIds=[1258528, 1258529, 1258530])

activities = mc.execute(
    method='get_lead_activities',
    activityTypeIds=activity_list,
    nextPageToken=None,
    sinceDatetime='2018-09-26',
    # untilDatetime='2018-09-30',
    batchSize=None,
    listId=None,
    leadIds=[1258528, 1258529, 1258530])
print(activities)
for idx, activity in enumerate(activities):
Beispiel #7
0
export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_41_50/file_mkto_actlog_atype_41_50.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id = ""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a = 0
    for activities in mc.execute(method='get_lead_activities_yield',
                                 activityTypeIds=[
                                     '104', '106', '108', '110', '111', '112',
                                     '113', '114', '115', '145'
                                 ],
                                 nextPageToken=None,
                                 sinceDatetime=sys.argv[1],
                                 untilDatetime=sys.argv[2],
                                 listId=76446):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=[
                                        'MarketoGUID', 'Lead ID',
                                        'Activity Date', 'Activity Type ID',
                                        'Primary Attribute Value Id',
                                        'Primary Attribute Value', 'Attributes'
                                    ])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
Beispiel #8
0
x = dt.today().strftime('%Y-%m-%d')

#export_act = mc.execute(method='browse_programs')
#export_job_data = str((mc.execute(method='get_leads_export_job_file',job_id=export_job_id)),'utf-8')
tags  = ['Business Owner', 'US Content Type', 'Therapy']
csvfile= r'D:\marketdo\tags\Program_data_experiment.csv'

i = 1

print('going inside tags')

for t in tags:
    i = i
    
    try:
        tagNam = mc.execute(method='get_tag_by_name', name=str(t))
    
    except KeyError:
        tagNam = 'False'
    
    print('writing in df')
    
    df = pd.DataFrame.from_dict(tagNam, orient='columns').reset_index()
   
    df.to_csv(csvfile, sep=',', encoding='utf-8', mode='a', index=False)
    
    print('Success')

df.head()

tagNam = mc.execute(method='get_tag_by_name', name='Therapy')
Beispiel #9
0
export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_51_60/file_mkto_actlog_atype_51_60_live.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id = ""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a = 0
    for activities in mc.execute(method='get_lead_activities_yield',
                                 activityTypeIds=[
                                     '400', '401', '402', '403', '405', '406',
                                     '407', '408', '409', '410'
                                 ],
                                 nextPageToken=None,
                                 sinceDatetime=sys.argv[1],
                                 untilDatetime=sys.argv[2],
                                 listId=76414):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=[
                                        'MarketoGUID', 'Lead ID',
                                        'Activity Date', 'Activity Type ID',
                                        'Primary Attribute Value Id',
                                        'Primary Attribute Value', 'Attributes'
                                    ])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
from marketorestpython.client import MarketoClient
import sys, csv, os, pandas

export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_61_70/file_mkto_actlog_atype_61_70.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id =""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a=0
    for activities in mc.execute(method='get_lead_activities_yield', activityTypeIds=['100001'],
                                 nextPageToken=None, sinceDatetime=sys.argv[1], untilDatetime=sys.argv[2], listId=76446):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=['MarketoGUID', 'Lead ID', 'Activity Date', 'Activity Type ID',
                                             'Primary Attribute Value Id', 'Primary Attribute Value', 'Attributes'])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
                records1.set_value(index, 'MarketoGUID', item["marketoGUID"])
                records1.set_value(index, 'Lead ID', item["leadId"])
                if 'activityDate' in item:
                    records1.set_value(index, 'Activity Date', item["activityDate"])
                if 'activityTypeId' in item:
                    records1.set_value(index, 'Activity Type ID', item["activityTypeId"])
                if 'primaryAttributeValueId' in item:
                    records1.set_value(index, 'Primary Attribute Value Id', item["primaryAttributeValueId"])
Beispiel #11
0
export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_21_30/file_mkto_actlog_atype_21_30_live.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id = ""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a = 0
    for activities in mc.execute(method='get_lead_activities_yield',
                                 activityTypeIds=[
                                     '30', '31', '32', '34', '35', '36', '37',
                                     '38', '39', '40'
                                 ],
                                 nextPageToken=None,
                                 sinceDatetime=sys.argv[1],
                                 untilDatetime=sys.argv[2],
                                 listId=76414):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=[
                                        'MarketoGUID', 'Lead ID',
                                        'Activity Date', 'Activity Type ID',
                                        'Primary Attribute Value Id',
                                        'Primary Attribute Value', 'Attributes'
                                    ])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
Beispiel #12
0
    i = i

    munchkin_id = "417-HAK-797"  ### Enter Munchkin ID
    client_id = "d3d19bbc-c67d-4f34-b06c-6e525bd891ff"  ### enter client ID (find in Admin > LaunchPoint > view details)
    client_secret = "G8GS7iRVGQ7XaSteta8w3MU7w2GFFjqO"  ### enter client secret (find in Admin > LaunchPoint > view details)
    mc = MarketoClient(munchkin_id, client_id, client_secret)

    #Lead Activity Code
    x = dt.today().strftime('%Y-%m-%d')

    print('fetching json for ' + str(t))

    try:
        tag = mc.execute(method='get_program_by_tag_type',
                         tagType='US Content Type',
                         tagValue=str(t))

    except KeyError:
        tag = 'False'
        continue

    df = pd.DataFrame.from_dict(tag, orient='columns').reset_index()

    dict = df['tags'].apply(lambda x: x[2])
    df['tagType'] = dict.apply(lambda x: x['tagType'])
    df['tagValue'] = dict.apply(lambda x: x['tagValue'])

    df = df[[
        'index', 'id', 'name', 'description', 'createdAt', 'updatedAt', 'url',
        'type', 'channel', 'folder', 'status', 'workspace', 'tags', 'tagType',
Beispiel #13
0
from marketorestpython.client import MarketoClient
munchkin_id = "473-EOD-147"  # fill in Munchkin ID, typical format 000-AAA-000
client_id = "cc3b4926-4e51-4948-b7d3-3b9e49fd82bb"  # enter Client ID from Admin > LaunchPoint > View Details
client_secret = "1DY40K34m3RM0sHJ8qNFfcO9mMYsXSm9"  # enter Client ID and Secret from Admin > LaunchPoint > View Details
mc = MarketoClient(munchkin_id, client_id, client_secret)

# Get Lead by Id
# lead = mc.execute(method='get_lead_by_id', id=1258528, fields=['firstName', 'middleName', 'lastName', 'department'])
# print (lead)
lead = mc.execute(method='get_lead_by_id', id=1258528)
print(lead)
from marketorestpython.client import MarketoClient
munchkin_id = "473-EOD-147"  # fill in Munchkin ID, typical format 000-AAA-000
client_id = "cc3b4926-4e51-4948-b7d3-3b9e49fd82bb"  # enter Client ID from Admin > LaunchPoint > View Details
client_secret = "1DY40K34m3RM0sHJ8qNFfcO9mMYsXSm9"  # enter Client ID and Secret from Admin > LaunchPoint > View Details
mc = MarketoClient(munchkin_id, client_id, client_secret)

# #Get Multiple Leads by List Id #2681
leads1 = mc.execute(
    method='get_multiple_leads_by_list_id',
    listId='2681',
    fields=['email', 'firstName', 'lastName', 'company', 'postalCode'],
    batchSize=None)

# Write leads into a file
import pickle
with open('outfile.txt', 'wb') as fp:
    pickle.dump(leads1, fp)

# with open('outfile.txt', 'rb') as fp:
#     leads = pickle.load(fp)

# #Get Multiple Leads by List Id Yield (Generator)
# for leads in mc.execute(method='get_multiple_leads_by_list_id_yield', listId='676',
#                 fields=['email','firstName','lastName'], batchSize=None):
#     print(len(leads)) vv vvvvvvvv
Beispiel #15
0
export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_31_40/file_mkto_actlog_atype_31_40.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id = ""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a = 0
    for activities in mc.execute(method='get_lead_activities_yield',
                                 activityTypeIds=[
                                     '41', '42', '43', '44', '45', '46', '47',
                                     '48', '101', '102'
                                 ],
                                 nextPageToken=None,
                                 sinceDatetime=sys.argv[1],
                                 untilDatetime=sys.argv[2],
                                 listId=76446):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=[
                                        'MarketoGUID', 'Lead ID',
                                        'Activity Date', 'Activity Type ID',
                                        'Primary Attribute Value Id',
                                        'Primary Attribute Value', 'Attributes'
                                    ])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
tag_type = ['US Content Type', 'Business Owner', 'Therapy']

csvfile = r'D:\marketdo\tags\output_latest3.csv'

#Lead Activity Code
x = dt.today().strftime('%Y-%m-%d')

i = 1

for x in tag_type:

    i = i

    try:
        tagTyp = mc.execute(method='get_tag_by_name', name=str(x))

    except KeyError:
        tagTyp = 'False'
        if tagTyp == 'False':
            print('No tag values were fetched for tag type: ' + str(x) + '\n')
        continue

    df_tval = pd.DataFrame.from_dict(tagTyp, orient='columns')
    tag_values = df_tval['allowableValues'][0]
    tag_values = tag_values.strip('][')
    tag_values = tag_values.split(", ")

    j = 1

    for t in tag_values:
def identify_broken_emails():
    munchkin_id = os.getenv('MUNCHKIN_ID')
    client_id = os.getenv('CLIENT_ID')
    client_secret = os.getenv('CLIENT_SECRET')
    api_limit = None
    max_retry_time = None
    mc = MarketoClient(munchkin_id, client_id, client_secret, api_limit,
                       max_retry_time)

    fieldnames = ["email", "id"]
    inputListID = 1038
    outputListID = 1037
    brokenLeads = []
    brokenIDs = []

    # identify invalid emails, i.e. emails with the following errors:
    # missing recipient name, missing @ symbol, missing domain name, missing top level domain
    # Note: ignores blank emails
    for leads in mc.execute(method='get_multiple_leads_by_list_id_yield',
                            listId=inputListID,
                            fields=fieldnames,
                            batchSize=None,
                            return_full_result=False):
        for lead in leads:
            if lead["email"]:
                if str(lead["email"])[0] == '@':
                    brokenLeads.append(lead)
                    brokenIDs.append(lead["id"])
                elif '@' not in str(lead["email"]):
                    brokenLeads.append(lead)
                    brokenIDs.append(lead["id"])
                else:
                    domain = str(lead["email"]).split('@')[1]
                    if domain[0] == '.':
                        brokenLeads.append(lead)
                        brokenIDs.append(lead["id"])
                    elif '.' not in domain:
                        brokenLeads.append(lead)
                        brokenIDs.append(lead["id"])

    # add broken leads to Change log
    for lead in brokenLeads:
        Change.objects.create(workflow='Identify Broken Emails',
                              timestamp=timezone.now(),
                              marketo_id=lead["id"],
                              changed_field="N/A",
                              old_value=lead["email"],
                              new_value=lead["email"])
    # add broken leads to output list
    counter = 0
    while (counter < len(brokenIDs)):
        lead = mc.execute(method="add_leads_to_list",
                          listId=outputListID,
                          id=brokenIDs[counter:counter + 300])
        counter += 300
    # remove broken leads from input list
    counter = 0
    while (counter < len(brokenIDs)):
        lead = mc.execute(method='remove_leads_from_list',
                          listId=inputListID,
                          id=brokenIDs[counter:counter + 300])
        counter += 300

    print("[" + str(timezone.now()) +
          "] COMPLETED WORKFLOW: identify broken emails")
export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_11_20/file_mkto_actlog_atype_11_20.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id = ""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a = 0
    for activities in mc.execute(method='get_lead_activities_yield',
                                 activityTypeIds=[
                                     '13', '19', '21', '22', '23', '24', '25',
                                     '26', '27', '29'
                                 ],
                                 nextPageToken=None,
                                 sinceDatetime=sys.argv[1],
                                 untilDatetime=sys.argv[2],
                                 listId=76446):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=[
                                        'MarketoGUID', 'Lead ID',
                                        'Activity Date', 'Activity Type ID',
                                        'Primary Attribute Value Id',
                                        'Primary Attribute Value', 'Attributes'
                                    ])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
Beispiel #19
0
export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_1_10/file_mkto_actlog_atype_1_10.csv'

# SPECIFY CLIENT CREDENTIALS
munchkin_id = ""
client_id = ""
client_secret = ""

mc = MarketoClient(munchkin_id, client_id, client_secret)

if __name__ == "__main__":
    a = 0
    for activities in mc.execute(method='get_lead_activities_yield',
                                 activityTypeIds=[
                                     '1', '2', '3', '6', '7', '8', '9', '10',
                                     '11', '12'
                                 ],
                                 nextPageToken=None,
                                 sinceDatetime=sys.argv[1],
                                 untilDatetime=sys.argv[2],
                                 listId=76446):

        records1 = pandas.DataFrame(index=range(0, len(activities)),
                                    columns=[
                                        'MarketoGUID', 'Lead ID',
                                        'Activity Date', 'Activity Type ID',
                                        'Primary Attribute Value Id',
                                        'Primary Attribute Value', 'Attributes'
                                    ])

        for index, item in enumerate(activities):
            if int(item["marketoGUID"]) > int(sys.argv[3]):
Beispiel #20
0
from marketorestpython.client import MarketoClient

munchkin_id = "473-EOD-147"  # fill in Munchkin ID, typical format 000-AAA-000
client_id = "cc3b4926-4e51-4948-b7d3-3b9e49fd82bb"  # enter Client ID from Admin > LaunchPoint > View Details
client_secret = "1DY40K34m3RM0sHJ8qNFfcO9mMYsXSm9"  # enter Client ID and Secret from Admin > LaunchPoint > View Details
mc = MarketoClient(munchkin_id, client_id, client_secret)

# Get Lead by Id
lead = mc.execute(method='get_lead_by_id',
                  id=1258528,
                  fields=['firstName', 'middleName', 'lastName', 'department'])
print(lead)
lead = mc.execute(method='get_lead_by_id', id=1258528)
print(lead)
Beispiel #21
0
def update_country_by_state():
    munchkin_id = os.getenv('MUNCHKIN_ID')
    client_id = os.getenv('CLIENT_ID')
    client_secret = os.getenv('CLIENT_SECRET')
    api_limit = None
    max_retry_time = None
    mc = MarketoClient(munchkin_id, client_id, client_secret, api_limit,
                       max_retry_time)

    fieldnames = ["state", "country", "id"]
    inputListID = 1038
    outputListID = 1035
    oldCountries = {}
    updatedLeads = []
    updatedIDs = []

    # if state field is filled in, update country to "United States"
    # if country field is "US", update country to "United States"
    for leads in mc.execute(method='get_multiple_leads_by_list_id_yield',
                            listId=inputListID,
                            fields=fieldnames,
                            batchSize=None,
                            return_full_result=False):
        for lead in leads:
            if not lead["country"]:
                if lead["state"]:
                    oldCountries[lead["id"]] = lead["country"]
                    lead["country"] = "United States"
                    updatedLeads.append(lead)
            elif str(lead["country"]) == "US":
                oldCountries[lead["id"]] = lead["country"]
                lead["country"] = "United States"
                updatedLeads.append(lead)
    counter = 0
    while (counter < len(updatedLeads)):
        lead = mc.execute(method="create_update_leads",
                          leads=updatedLeads[counter:counter + 300],
                          action="updateOnly",
                          lookupField="id")
        for response in lead:
            if response["status"] == "updated":
                updatedIDs.append(response["id"])
        counter += 300

    # add updated leads to change log and output list
    for lead in updatedLeads:
        if lead["id"] in updatedIDs:
            Change.objects.create(workflow='Update Country By State',
                                  timestamp=timezone.now(),
                                  marketo_id=lead['id'],
                                  changed_field='country',
                                  old_value=oldCountries[lead["id"]],
                                  new_value=lead['country'])
    counter = 0
    while (counter < len(updatedIDs)):
        lead = mc.execute(method="add_leads_to_list",
                          listId=outputListID,
                          id=updatedIDs[counter:counter + 300])
        counter += 300

    print("[" + str(timezone.now()) +
          "] COMPLETED WORKFLOW: update country by state")