Constant Contact API ( http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST )を介して特定のリストに連絡先を一括ロードする必要があります。
以下と同じ JSON 文字列を使用して、次の API GUI Web サイトに連絡先を正常に追加できます ( 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 呼び出しの 2 つが異なる結果を生成するにはどうすればよいですか?また、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)