我需要通过 Constant Contact API ( http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST ) 将联系人批量加载到特定列表。
我可以使用与以下相同的 JSON 字符串成功地将联系人添加到以下 API GUI 网站(https://constantcontact.mashery.com/io-docs(找到 Tab POST 'add contact' to collection):
update_contact = {"lists": [{"id": "1"}],"email_addresses": [{"email_address": "yasmin1.abob19955@gmail.com"}],"first_name": "Ronald","last_name": "Martone"}
但是,当我在我的 python 代码中运行相同的 JSON 字符串时,我收到错误 400,来自我的响应对象的错误消息如下:
[{"error_key":"query.param.invalid","error_message":"The query parameter first_name is not supported."},
{"error_key":"query.param.invalid","error_message":"The query parameter last_name is not supported."},{"error_key":"query.param.invalid","error_message":"The query parameter lists is not supported."},{"error_key":"query.param.invalid","error_message":"The query parameter email_addresses is not supported."}]
两个相同的 API 调用如何产生不同的结果?如何让我的 python 代码工作?
代码:
import requests
headers = {
'Authorization': 'Bearer X',
'X-Originating-Ip': '1',
'Content-Type': 'application/json'
}
update_contact = {"lists": [{"id": "1"}],"email_addresses": [{"email_address": "yasmin1.abob19955@gmail.com"}],"first_name": "Ronald","last_name": "Martone"}
r_2 = requests.post('https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_OWNER&api_key=x', headers=headers ,params = update_contact)
print(r_2.text)