mailchimp / APIv3-examples

Straight-forward examples of working with v3 the MailChimp API without any wrapper libraries
https://mailchimp.com/developer/
BSD 3-Clause "New" or "Revised" License
85 stars 34 forks source link

Python lacks POST request example #21

Open Hendler opened 9 years ago

Hendler commented 9 years ago

e.g. Maybe one for adding members:

mailchimp_api_root = "https://" + shard + ".api.mailchimp.com/3.0/"
endpoint = mailchimp_api_root + "lists/" + mailchimp_list_id + "/members/"
response = requests.post(endpoint, auth=('apikey', mailchimp_api_key), json=payload, verify=False)
dimmg commented 8 years ago

also you should json.dumps(...) the payload you are sending in the data, otherwise it'll result in a JSON Parse Error.

payload = json.dumps({"email_address": email, "status": "subscribed"})
response = requests.post(endpoint, auth=('apikey', mailchimp_api_key), data=payload)
delink commented 7 years ago

That's not true, @dimmg . If you use the "json" attribute instead of the "data" attribute, it will do the json.dumps() for you.