How to use marketorestpython - 10 common examples

To help you get started, we’ve selected a few marketorestpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
'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'
github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
def client():
    return MarketoClient('123-FDY-456', 'randomclientid', 'supersecret')
github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
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
github jepcastelein / marketo-rest-python / test_script.py View on Github external
logger = logging.getLogger()

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


def test_create_update_leads():
    random_number = randint(100, 999)
github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
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'
        }
github jepcastelein / marketo-rest-python / test_script.py View on Github external
logger.info('found {} campaigns with maxReturn=10'.format(len(campaigns)))
        break
    assert len(first_campaigns) > 20 and len(second_campaigns) == 2 and len(third_campaigns) == 10


def test_activate_smart_campaign():
    campaign = mc.execute(method='activate_smart_campaign', id=1109)
    assert campaign[0]['id'] == 1109


def test_deactivate_smart_campaign():
    campaign = mc.execute(method='deactivate_smart_campaign', id=1109)
    assert campaign[0]['id'] == 1109


mc2 = MarketoClient(munchkin_id=MUNCHKIN_ID, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, max_retry_time=30)


def test_max_retry_time():
    day = 1
    time_elapsed = 0
    for i in range(11):
        start_time = time.time()
        export_filter = {
          "createdAt": {
             "startAt": "2018-07-0{}".format(day),
             "endAt": "2018-07-0{}".format(day+1)
          },
          "activityTypeIds": [1]
        }
        job = mc2.execute(method='create_activities_export_job', filters=export_filter)
        job_id = job[0]['exportId']
github jepcastelein / marketo-rest-python / marketorestpython / client.py View on Github external
if filterValues is None: raise ValueError("Invalid argument: required argument filter_values is none.")
        args = {
            'access_token': self.token,
            '_method': 'GET'
        }
        filterValues = filterValues.split() if type(filterValues) is str else filterValues
        data=[('filterValues',(',').join(filterValues)), ('filterType', filterType)]
        if fields is not None:
            data.append(('fields',fields))
        if batchSize is not None:
            data.append(('batchSize',batchSize))
        result_list = []
        while True:
            result = HttpLib().post(self.host + "/rest/v1/opportunities.json", args, data, mode='nojsondumps')
            if result is None: raise Exception("Empty Response")
            if not result['success'] : raise MarketoException(result['errors'][0])
            result_list.extend(result['result'])
            if len(result['result']) == 0 or 'nextPageToken' not in result:
                break
            args['nextPageToken'] = result['nextPageToken']
        return result_list
github jepcastelein / marketo-rest-python / marketorestpython / client.py View on Github external
self.authenticate()
        if filterType is None: raise ValueError("Invalid argument: required argument filterType is none.")
        if filterValues is None: raise ValueError("Invalid argument: required argument filter_values is none.")
        args = {
            'access_token': self.token,
            '_method': 'GET'
        }
        filterValues = filterValues.split() if type(filterValues) is str else filterValues
        data=[('filterValues',(',').join(filterValues)), ('filterType', filterType)]
        if fields is not None:
            data.append(('fields',fields))
        if batchSize is not None:
            data.append(('batchSize',batchSize))
        result_list = []
        while True:
            result = HttpLib().post(self.host + "/rest/v1/salespersons.json", args, data, mode='nojsondumps')
            if result is None: raise Exception("Empty Response")
            if not result['success'] : raise MarketoException(result['errors'][0])
            result_list.extend(result['result'])
            if len(result['result']) == 0 or 'nextPageToken' not in result:
                break
            args['nextPageToken'] = result['nextPageToken']
        return result_list
github jepcastelein / marketo-rest-python / marketorestpython / client.py View on Github external
def update_email(self, id, name=None, description=None):
        self.authenticate()
        if id is None: raise ValueError("Invalid argument: required argument id is none.")
        args = {
            'access_token': self.token
        }
        if name is not None:
            args['name'] = name
        if description is not None:
            args['description'] = description
        result = HttpLib().post(self.host + "/rest/asset/v1/email/" + str(id) + ".json", args)
        if result is None: raise Exception("Empty Response")
        if not result['success'] : raise MarketoException(result['errors'][0])
        return result['result']
github jepcastelein / marketo-rest-python / marketorestpython / client.py View on Github external
def get_program_by_tag_type(self, tagType, tagValue):
        self.authenticate()
        if tagType is None: raise ValueError("Invalid argument: required argument tagType is none.")
        if tagValue is None: raise ValueError("Invalid argument: required argument tagValue is none.")
        args = {
            'access_token': self.token,
            'tagType': tagType,
            'tagValue': tagValue
        }
        result = HttpLib().get(self.host + "/rest/asset/v1/program/byTag.json", args)
        if result is None: raise Exception("Empty Response")
        if not result['success']: raise MarketoException(result['errors'][0])
        return result['result']

marketorestpython

Python Client for the Marketo REST API

MIT
Latest version published 8 months ago

Package Health Score

59 / 100
Full package analysis

Similar packages