I've talked before about using Postman to make REST API calls, and it's perfectly fine for one off calls for testing.. but what about those times when you need a full on programming language to upsert leads or custom objects, or perform some other function using the REST API? Well, you can write your own libraries to make it easier, or you can leverage the Marketo Rest Python library created by Jep Castelein
This article will serve as a step by step guide for getting up and running and making basic hello world calls using Python.
Products
We'll be using the following, all of which are free.
Python (Download the latest version here)
pip for Python - A great installer program we'll use to install the library
Marketo-Python-REST library
PyCharm - A great Free IDE (the Community Edition is free)
Step 1 - Python 3.x.x
In MacOS , you'll notice that python 2.7 comes pre installed, but its perfectly acceptable to run more than one version of Python. Download the Python DMG file and install it. Make sure it installed by opening up a terminal and typing python3. Simple!
Step 2 - PIP
You can follow the directions here, downloading get-pip.py from https://bootstrap.pypa.io/get-pip.py , then running the following command, making sure you run it against Python 3.51 as follows
python3 get-pip.py
Seriously. It's that easy.
Step 3 - The Marketo Rest Python Library
Again, very simple. At the command line, ensure you have pip installed by typing
pip -V
It should indicate that you're installed on version 3.x.x (depending on your version)
Note that you might have installed it as pip3, so check that.
Next, type the following (adding sudo on the mac)
pip install marketorestpython
It should look rather like this:
Step 4 - PyCharm
You guessed it. Download the dmg file for mac, and install it.
Create a project called "Marketo Python" and get creative.. maybe you want to set up folders for your different tasks. For this one, I created a hello world folder
Create a new file, and enter the following substituting your own Marketo instance credentials
from marketorestpython.client import MarketoClient
munchkin_id = "your value"
client_id = "your value"
client_secret = "your value"
mc = MarketoClient(munchkin_id, client_id, client_secret)
lead = mc.execute(method='get_lead_by_id', id= 1001)
print(lead)
The library is quite well documented here.. so get creative! Let us know in the comments how you're using it! https://github.com/jepcastelein/marketo-rest-python
Update!
If you get an error like "HTTP Get Exception! Retrying....." and / or "SSLV3_ALERT_HANDSHAKE_FAILURE" in Mac OS Sierra, you likely need Install requests
with extra security packages using: pip install requests[security]
. It's further discussed in this requests issue on github.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.