Skip to content

Instantly share code, notes, and snippets.

@dimmg
Created February 4, 2016 16:33
Show Gist options
  • Save dimmg/58741c99988e9ea6f99e to your computer and use it in GitHub Desktop.
Save dimmg/58741c99988e9ea6f99e to your computer and use it in GitHub Desktop.
mailchimp v3.0 with python
import json
import requests
# mailchimp api_key and list_id
MAILCHIMP_API_KEY = 'da29dawdn2138dwdawdn21k38-us10'
MAILCHIMP_LIST_ID = 'dfi2ndwa2'
us_ = MAILCHIMP_API_KEY.split('-')[1]
mailchimp_api_root = "https://" + us_ + ".api.mailchimp.com/3.0/"
endpoint = mailchimp_api_root + "lists/" + MAILCHIMP_LIST_ID + "/members/"
# subscribing user to a list
payload = json.dumps({"email_address": "[email protected]", "status": "subscribed"})
response = requests.post(endpoint, auth=('apikey', MAILCHIMP_API_KEY), data=payload)
# retrieving all users from a list
response = requests.get(endpoint, auth=('apikey', MAILCHIMP_API_KEY))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment