Marketo API和Python,发布请求失败 [英] Marketo API and Python, Post request failing
问题描述
我们正在尝试编写一个小型库,以使用Python与您的API进行交互.我们尝试使用cURL推动潜在客户,但进展顺利:
We are trying to write a small library to interact with your API using Python. We tried to push a lead using cURL, and it went well:
1.-获取OAuth令牌:
1.- Get the OAuth token:
curl "https://700-HZF-887.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id=45811e23-3223-4cc4-811e-e00f0000acc8&client_secret=000000000000000000000"
响应:
{"access_token":"00000000000000000aaaaaaaaaaaaaaa:sj","token_type":"bearer","expires_in":1895,"scope":"fernando@email.com"}
2.-创建/更新销售线索:
2.- Create/Update a lead:
curl -H 'Content-Type: application/json' -H 'Authorization: Bearer 00000000000000000aaaaaaaaaaaaaaa:sj' -d '{"action": "createOnly", "input": [{"LastName": "LastNameTest", "email": "testemail@email.com", "FirstName": "TestName", "MobilePhone": "12345"}]}' https://700-HZF-887.mktorest.com/rest/v1/leads.json
最后一条命令成功响应,并且线索出现在Marketo的仪表板上.到目前为止一切顺利.
This last command responds with success and the lead appears on Marketo's Dashboard. So far so good.
我们正在尝试使用请求库在Python中实现相同的目的:
We are trying to achieve the same thing in Python using the requests library:
我们首先创建两个字典,有效载荷和标头:
We first create two dictionaries, payload and headers:
payload = {'action': 'createOnly', 'input': [{'email': email, 'FirstName': first_name, 'LastName': last_name, 'MobilePhone': phone}]}
headers = {'Content-type': 'application/json', 'Authorization:': 'Bearer ' + str(token['access_token'])}
然后我们触发发布请求:
And then we fire the post request:
base_url = 'https://700-HZF-887.mktorest.com/rest/v1/leads.json'
response = requests.post(base_url, data=payload, headers=headers)
其中令牌变量是一个列表,其中包含在代码中之前获得的访问令牌. 运行代码时,我得到以下信息:
Where token variable is a list that contains the access token obtained before in the code. When I ran the code I get the following:
Headers: {'Content-type': 'application/json', 'Authorization:': 'Bearer f020000-0000-4001-a00d-c040000d0000:dw'}
Payload: {'action': 'createOnly', 'input': [{'LastName': 'testname', 'email': 'test@email.com', 'FirstName': 'testfirstname', 'MobilePhone': '12345'}]}
Response: {"requestId":"3000#147f4860000","success":false,"errors":[{"code":"600","message":"Access token not specified"}]}
您知道我为什么真的在请求中添加令牌时,为什么知道为什么未指定代码600 Access令牌作为响应?
Do you know why am I getting the code:600 Access token not specified as a response when I think I really am adding the token in my request?
推荐答案
授权标头中还有一个额外的:".删除它,你应该会很好.
There is an extra ":" in the Authorization header. Remove it and you should be good.
这篇关于Marketo API和Python,发布请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!