How can I subscribe to a list using the python mailchimp API version 2.0?

I want to subscribe to a list using Mailchimp API 2.0 and the official python mailchimp package . I can not find direct documentation for how.

+6
source share
2 answers

Before you begin, you need to get your API key and list ID by logging in to Mailchimp.

To get the API key, go to Accounts> Extras and generate the API key. To get the list identifier, go to List> My list> Settings> List name and default values.

Then make sure you install the python mailchimp package:

pip install mailchimp 

Finally:

 import mailchimp API_KEY = 'my-api-key' LIST_ID = 'my-list-id' api = mailchimp.Mailchimp(API_KEY) api.lists.subscribe(LIST_ID, {'email': ' email@example.com '}) 
+16
source

In addition to seddonym's answer: if you want to add a name or other information about the subscriber, you can do this by adding merge_vars to the function call as follows:

 api.lists.subscribe(LIST_ID, {'email': email}, merge_vars={'FNAME':fname,'LNAME':lname}) 

See here for all options: https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

+5
source

Source: https://habr.com/ru/post/978779/


All Articles