Getting Marketo data in Python — Marketo rest API and Python API

Sophia Yang, Ph.D.
3 min readDec 17, 2019
image coming from

There are two ways I have used to get Marketo data in Python. First is to use Marketo rest API directly. Second is to use the marketo Python API marketorestpython. I really like the marketorestpython library and I highly recommend everyone to use this library. But in this article, I am going to talk about both approach.

Marketo rest API

First, we need to get client_id, client_secret, munchkin_id/instance URL information. Client Id and Client Secret can be set up via LaunchPoint and they can be found under Admin > LaunchPoint > View Details . And Munchkin Account ID can be found under Admin > Integration > Munchkin menu. munchkin_id is also part of the instance URL, which can be found under Admin > Integration > Web Services > REST API > Identity.

munchkin_id = ""
client_id = ""
client_secret= ""
args = {'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret}
host = f'https://{munchkin_id}'

Second, we need to get access token and next page token. Since we have all the credentials ready. We can use the Python requests library and do an HTTP GET request to get tokens.

import requests
data = requests.get(host+'/identity/oauth/token',
params ={'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret},
headers= {'Accept-Encoding': 'gzip'}).json()
token = data['access_token']
data_nextPageToken = requests.get(host+'/rest/v1/activities/pagingtoken.json',
params = {'access_token':token,
nextPageToken = data_nextPageToken['nextPageToken']

Next, we can use the access token to get the activities and leads data from Marketo.

act1 = requests.get(host+'/rest/v1/activities.json', 
params ={'access_token': token,
'nextPageToken': nextPageToken,
leads1 = requests.get(host+'/rest/v1/leads.json',
params ={'access_token': token…
Sophia Yang, Ph.D.