Marketo REST Python Client

0.5.25 · active · verified Thu Apr 16

MarketoRestPython is a Python client library that wraps the Marketo REST API, providing a convenient interface for interacting with Marketo's marketing automation platform. It handles common concerns such as authentication, error handling, and API rate limiting. The library is actively maintained, with version 0.5.25 being the latest, and receives frequent updates to support new Marketo API features and address bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the MarketoClient using credentials obtained from environment variables and then fetches the available Marketo activity types. This demonstrates basic client setup and an initial API call, including checking the 'success' field in the response.

import os
from marketorestpython.client import MarketoClient

munchkin_id = os.environ.get('MARKETO_MUNCHKIN_ID', 'YOUR_MUNCHKIN_ID')
client_id = os.environ.get('MARKETO_CLIENT_ID', 'YOUR_CLIENT_ID')
client_secret = os.environ.get('MARKETO_CLIENT_SECRET', 'YOUR_CLIENT_SECRET')

if not all([munchkin_id, client_id, client_secret]):
    raise ValueError("Marketo credentials (MUNCHKIN_ID, CLIENT_ID, CLIENT_SECRET) must be set as environment variables or provided directly.")

try:
    # Initialize the Marketo client
    # api_limit and max_retry_time are optional parameters for fine-tuning
    mc = MarketoClient(munchkin_id, client_id, client_secret, api_limit=None, max_retry_time=300)

    # Example: Get activity types
    print("Fetching Marketo Activity Types...")
    activity_types = mc.execute(method='get_activity_types')

    if activity_types and activity_types.get('success'):
        print(f"Successfully retrieved {len(activity_types['result'])} activity types.")
        for activity_type in activity_types['result'][:5]: # Print first 5 for brevity
            print(f"  ID: {activity_type['id']}, Name: {activity_type['name']}")
    elif activity_types and 'errors' in activity_types:
        print(f"Error fetching activity types: {activity_types['errors']}")
    else:
        print("Failed to retrieve activity types with an unknown error.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →