Skip to content

Instantly share code, notes, and snippets.

@octern
Last active January 10, 2020 16:24
Show Gist options
  • Save octern/64427c1d306a14f60434b64bac70b129 to your computer and use it in GitHub Desktop.
Save octern/64427c1d306a14f60434b64bac70b129 to your computer and use it in GitHub Desktop.
Add MailChimp subsciber via API using Python with mailchimp3
# to install module: pip install mailchimp3
from mailchimp3 import MailChimp as mc
api_key = "" #your api key
username = "" #username you use to log in to mailchimp
audience_id = "" #hex audience ID, as string, from Audience > Manage Audience > Settings > Audience name and defaults (some documentation refers to these as "lists"; the name seems to have been changed to "audiences")
subscriber_email = "" #email address
status = "" #"pending" to send an opt-in email, "subscribed" if the user already opted in, or "transactional" if they don't need to opt in
client=mc(mc_api=api_key, mc_user=username)
client.lists.members.create(list_id=list_id, data={"email_address":subscriber_email, "status":status})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment