mustacheMcGee
mustacheMcGee

Reputation: 501

Python Requests + Marketo REST API

I am trying to talk to my Marketo Instance using Jupyter (Anaconda) and Requests package. I'm OK with creating the auth token, but getting stuck on making the actual call to the endpoint.

host = "https://my_mtko_instance.com"    
leadId = "13000000"
endpoint = "/rest/v1/lead/" + leadId + ".json"
auth_token =  "?access_token=" + mkto_token
getLead = requests.get(host+endpoint+leadId+auth_token)
print(host+endpoint+auth_token)
getLead.json()

I get a `JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Interestingly, I'm able to click the URL from print() and that takes me to a JSON looking response in my browser.

Upvotes: 2

Views: 510

Answers (1)

dferenc
dferenc

Reputation: 8126

I think the problem lies in how you assemble the url for the get request.

Please note, that the correct format of the endpoint is:
https://<mkto_instance>.mktorest.com/rest/v1/lead/{leadId}.json
However, with the host+endpoint+leadId+auth_token format you insert the leadId variable twice, as the endpoint variable already contains it.

Change the call to requests.get(host+endpoint+auth_token) and it should work fine.

Upvotes: 2

Related Questions