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")
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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")
Esempio n. 6
0
    def init_app(self, app):
        analytics_type = app.config.get('USER_ANALYTICS_TYPE', 'FakeAnalytics')

        marketo_munchkin_id = ''
        marketo_munchkin_private_key = ''
        marketo_client_id = ''
        marketo_client_secret = ''
        marketo_lead_source = ''
        executor = NullExecutor()

        if analytics_type == 'Marketo':
            marketo_munchkin_id = app.config['MARKETO_MUNCHKIN_ID']
            marketo_munchkin_private_key = app.config[
                'MARKETO_MUNCHKIN_PRIVATE_KEY']
            marketo_client_id = app.config['MARKETO_CLIENT_ID']
            marketo_client_secret = app.config['MARKETO_CLIENT_SECRET']
            marketo_lead_source = app.config['MARKETO_LEAD_SOURCE']

            logger.debug('Initializing marketo with keys: %s %s %s',
                         marketo_munchkin_id, marketo_client_id,
                         marketo_client_secret)

            executor = ThreadPoolExecutor(max_workers=1)

        marketo_client = MarketoClient(marketo_munchkin_id, marketo_client_id,
                                       marketo_client_secret)
        client_wrapper = _MarketoAnalyticsClient(marketo_client,
                                                 marketo_munchkin_private_key,
                                                 marketo_lead_source)
        user_analytics = AsyncExecutorWrapper(client_wrapper, executor)

        # register extension with app
        app.extensions = getattr(app, 'extensions', {})
        app.extensions['user_analytics'] = user_analytics
        return user_analytics
def test_marketo_client(client):
    assert client.host == 'https://123-FDY-456.mktorest.com'
    assert client.client_id == 'randomclientid'
    assert client.client_secret == 'supersecret'
    assert client.API_CALLS_MADE == 0
    assert client.API_LIMIT is None

    client = MarketoClient('123-FDY-456', 'randomclientid', 'supersecret', 20)
    assert client.API_LIMIT == 20
def test_authenticate(m_client_api_call, client):
    m_client_api_call.return_value = None
    with pytest.raises(Exception):
        client.authenticate()

    access_token = "cdf01657-110d-4155-99a7-f986b2ff13a0:int"
    token_type = "bearer"
    expires_in = 3599
    scope = "*****@*****.**"
    m_client_api_call.return_value = {
        "access_token": access_token,
        "token_type": token_type,
        "expires_in": expires_in,
        "scope": scope
    }

    client.authenticate()
    m_client_api_call.assert_called_with(
        'get', client.host + '/identity/oauth/token', {
            'grant_type': 'client_credentials',
            'client_id': client.client_id,
            'client_secret': client.client_secret,
        })

    assert client.token == access_token
    assert client.token_type == token_type
    assert client.expires_in == expires_in
    assert client.valid_until > time.time()
    assert client.scope == scope

    # credentials should still be valid
    client.authenticate()
    assert m_client_api_call.call_count == 2

    # test error handling
    client = MarketoClient('123-FDY-456', 'randomclientid', 'supersecret')
    m_client_api_call.return_value = {
        'error': 'invalid_client',
        'error_description': 'invalid secret'
    }
    with pytest.raises(Exception) as excinfo:
        client.authenticate()
        assert excinfo.value == 'invalid secret'
Esempio n. 9
0
def main():
    # getting Marketo Credentials
    with open('config.json') as Variable_file:
        variable = json.load(Variable_file)

    munchkin_id = variable["Marketo_Credentials"]["Munchkin_Id"]
    client_id = variable["Marketo_Credentials"]["Client_Id"]
    client_secret = variable["Marketo_Credentials"]["Client_Secret"]
    try:
        mc = MarketoClient(munchkin_id, client_id, client_secret)
    except Exception as e:
        # sendErrorMail(variable['email'], e)
        print("error sent in email", e)

    postgresHost = variable["PostgreSQL"]["PostgreSQL_Host"]
    postgresDatabaseName = variable["PostgreSQL"]["PostgreSQL_Database_Name"]
    postgresSchemaName = variable["PostgreSQL"]["PostgreSQL_Schema_Name"]
    postgresUserName = variable["PostgreSQL"]["PostgreSQL_User_Name"]
    postgresPassword = variable["PostgreSQL"]["PostgreSQL_Password"]
    postgresPort = variable["PostgreSQL"]["PostgreSQL_Port"]
    tableProgramsInMarketo = variable["PostgreSQL"]["Table"]["Table_programs_in_marketo"]
    tableProgramData = variable["PostgreSQL"]["Table"]["Table_programs_data"]
    tableProgramsMembersData = variable["PostgreSQL"]["Table"]["Table_programs_members_data"]


    ''' Creating Schema and Using it as default'''
    try:
        conn = psycopg2.connect(dbname=postgresDatabaseName, user=postgresUserName, password=postgresPassword,
                                port=postgresPort)
        conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
        cursor = conn.cursor()
        cursor.execute('CREATE SCHEMA IF NOT EXISTS ' + postgresSchemaName + ';')
        cursor.execute("SET search_path TO " + postgresSchemaName)

    except:
        print("Error! Connection Failure.")
        # sendErrorMail(variable['email'], e)
        sys.exit()

    engine = create_engine(
        r'postgresql://' + postgresUserName + ':' + postgresPassword + '@' + postgresHost + ':' + str(
            postgresPort) + '/' + postgresDatabaseName)

    try:
        cursor.execute("Truncate Table " + tableProgramData)
        cursor.execute("Truncate Table " + tableProgramsInMarketo)
        cursor.execute("Truncate Table " + tableProgramsMembersData)
        programIds = get_programIds(mc)
        check_new_programs(engine, postgresSchemaName, tableProgramsInMarketo, programIds)
        get_programsData(mc, cursor, engine, postgresSchemaName, tableProgramsInMarketo, tableProgramData)
        get_membersData(mc, cursor, engine, postgresSchemaName, tableProgramsInMarketo, tableProgramsMembersData)
    except Exception as e:
        # sendErrorMail(variable['email'], e)
        print("error sent in email", e)
def test_api_call(m_http_lib, client):
    get_request_mock = Mock(return_value={
        'access_token': '1234',
        'expires_in': 1000,
        'scope': '1'
    })
    request_mock = Mock(get=get_request_mock)
    m_http_lib.return_value = request_mock
    args = (1, 2, 3)
    kwargs = {'a': 1, 'b': 2}
    client._api_call('get', '/test', *args, **kwargs)
    get_request_mock.assert_called_with(*(('/test', ) + args), **kwargs)
    assert client.API_CALLS_MADE == 1

    limit = 4
    client = MarketoClient('123-FDY-456', 'randomclientid', 'supersecret',
                           limit)
    with pytest.raises(Exception) as excinfo:
        for i in xrange(limit):
            client._api_call('get', '/test', *args, **kwargs)
        assert excinfo.value == {
            'message': 'API Calls exceeded the limit : %s' % limit,
            'code': '416'
        }
Esempio n. 11
0
    def init_app(self, app):
        analytics_type = app.config.get("USER_ANALYTICS_TYPE", "FakeAnalytics")

        marketo_munchkin_id = ""
        marketo_munchkin_private_key = ""
        marketo_client_id = ""
        marketo_client_secret = ""
        marketo_lead_source = ""
        executor = NullExecutor()

        if analytics_type == "Marketo":
            marketo_munchkin_id = app.config["MARKETO_MUNCHKIN_ID"]
            marketo_munchkin_private_key = app.config[
                "MARKETO_MUNCHKIN_PRIVATE_KEY"]
            marketo_client_id = app.config["MARKETO_CLIENT_ID"]
            marketo_client_secret = app.config["MARKETO_CLIENT_SECRET"]
            marketo_lead_source = app.config["MARKETO_LEAD_SOURCE"]

            logger.debug(
                "Initializing marketo with keys: %s %s %s",
                marketo_munchkin_id,
                marketo_client_id,
                marketo_client_secret,
            )

            executor = ThreadPoolExecutor(max_workers=1)

        marketo_client = MarketoClient(marketo_munchkin_id, marketo_client_id,
                                       marketo_client_secret)
        client_wrapper = _MarketoAnalyticsClient(marketo_client,
                                                 marketo_munchkin_private_key,
                                                 marketo_lead_source)
        user_analytics = AsyncExecutorWrapper(client_wrapper, executor)

        # register extension with app
        app.extensions = getattr(app, "extensions", {})
        app.extensions["user_analytics"] = user_analytics
        return user_analytics
Esempio n. 12
0
from marketorestpython.client import MarketoClient
import sys, csv, os, pandas

export_file = 'C:/Talend/JobFiles/Marketo/Export/ActivityLog/ActivityLog_AType_21_30/file_mkto_actlog_atype_21_30.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=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"])
from marketorestpython.client import MarketoClient
import sys, csv, os, pandas

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'
                                    ])
Esempio n. 14
0
from marketorestpython.client import MarketoClient
import sys, csv, os, pandas

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'
                                    ])
# -*- coding: utf-8 -*-

import pandas as pd
from datetime import datetime as dt, timedelta
from marketorestpython.client import MarketoClient

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)

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')
Esempio n. 16
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 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
Esempio n. 17
0
from marketorestpython.client import MarketoClient
import sys, csv, os, pandas

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'
                                    ])
Esempio n. 18
0
    'Branded HCP', 'Unbranded HCP', 'Branded Patient', 'Unbranded Patient',
    'Portfolio (including CDS)'
]

csvfile = r'd:/Program_data_tags.csv'

i = 1

for t in tags:

    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
def client():
    return MarketoClient('123-FDY-456', 'randomclientid', 'supersecret')
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")
Esempio n. 21
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)
Esempio n. 22
0
from marketorestpython.client import MarketoClient

client = MarketoClient('AAA-123-CC', 'randomclientid', 'secret')

print("All is good. MarketoClient initialized")
Esempio n. 23
0
import pandas as pd
from datetime import datetime as dt, timedelta
from marketorestpython.client import MarketoClient

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')

#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'
Esempio n. 24
0
# Google Auth
CREDS_FILE_PATH = Variable.get("creds_google", deserialize_json=True)
SCOPES = ["https://www.googleapis.com/auth/spreadsheets"]
CREDENTIALS = ServiceAccountCredentials.from_json_keyfile_dict(
    CREDS_FILE_PATH, SCOPES)
sheets_service = discovery.build("sheets",
                                 "v4",
                                 credentials=CREDENTIALS,
                                 cache_discovery=False)
gc = gspread.authorize(CREDENTIALS)

# Marketo Auth
mkto = Variable.get("creds_mkto", deserialize_json=True)
mc = MarketoClient(
    mkto["MKTO_CLIENT_MUNCHKIN"],
    mkto["MKTO_CLIENT_ID"],
    mkto["MKTO_CLIENT_SECRET"],
)

# ON24 Auth
web = Variable.get("creds_on24", deserialize_json=True)

# Json reference pulls
j = "event_"
son = "sto20"
ref = Variable.get(j + son, deserialize_json=True)
ref_doc_url = ref["REF_DOC"]  # Url for reference doc
ref_doc_sheet = ref["REF_DOC_SHEET"]  # sheet inside reference doc
ref_cols = ref["REF_DOC_COLS"]
ref_file_id = ref["EVENT_FINAL_DOC"]
ref_file_summ = ref["EVENT_FINAL_SUMM"]
Esempio n. 25
0
try:
    # Travis testing
    MUNCHKIN_ID = os.environ['MUNCHKIN_ID']
    CLIENT_ID = os.environ['CLIENT_ID']
    CLIENT_SECRET = os.environ['CLIENT_SECRET']
except KeyError:
    # local testing
    with open('conf.json', 'r', encoding='utf-8') as f:
        creds = json.loads(f.read())
    MUNCHKIN_ID = creds['munchkin_id']
    CLIENT_ID = creds['client_id']
    CLIENT_SECRET = creds['client_secret']

mc = MarketoClient(munchkin_id=MUNCHKIN_ID,
                   client_id=CLIENT_ID,
                   client_secret=CLIENT_SECRET)

segmentation_id = 1001

lead_id_1 = None
lead_id_2 = None
file_id = None
list_folder_id = None
new_folder_id = None
list_id = None
files_folder_id = None
bulk_lead_export_id = None
list_name = uuid.uuid4()

Esempio n. 26
0
# Data params
days = params.get('days')
start_date_str = params.get('start_date')
end_date_str = params.get('end_date')

leads_date_filter_type = params.get('leads_date_filter_type', "updatedAt")
leads_fields = params['leads_fields']
leads_primary_key = params.get('leads_primary_key')

activities_type_ids = params.get('activities_type_ids')
activities_fields = params['activities_fields']
activities_primary_key = params.get('activities_primary_key')

# Initialize MarketoClient
mc = MarketoClient(munchkin_id, client_id, client_secret)

# Date chunk setup
if days is None:
    start_date = datetime.strptime(start_date_str, short_dt_format)
    end_date = datetime.strptime(end_date_str, short_dt_format)
    days = (end_date - start_date).days + 1
else:
    start_date = date.today() - pd.Timedelta(days=days - 1)

assert days > 0, "'days' parameter must be > 0 if specified and 'start_date' must be < 'end_date' if specified"

full_chunks = m.floor(days / chunk_days)
leftover_days = days % chunk_days

chunk_list = []
Esempio n. 27
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):
Esempio n. 28
0
 def __init__(self):
     self.munchkin_id = 
     self.client_id = 
     self.client_secret = 
     self.mc = MarketoClient(self.munchkin_id, self.client_id, self.client_secret)
Esempio n. 29
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)
Esempio n. 30
0
from marketorestpython.client import MarketoClient
import sys, csv, os, pandas

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'
                                    ])