Subscribe from Python api v2

583 views
Skip to first unread message

Bohdan Anderson

unread,
Feb 13, 2014, 4:54:10 PM2/13/14
to mailchimp-...@googlegroups.com
This may be a really basic question, but I've been having trouble understanding the variables that need to passed to subscribe a user, here is what I'm doing so far.

import mailchimp

apikey = "<my api key>"
m
= mailchimp.Mailchimp(apikey)
list = m.lists.list()
id = list["data"][0]["id"]
webid
= list["data"][0]["web_id"]
m
.lists.subscribe(apikey,id,{"email":"myEmail...@gmail.com","leid":webid})


I'm not 100% sure of what Ids should be going where - is my "struct" wrong? -- I have no idea what "struct" means in the case of python. Any help would be appreciated, thanks.
 

Shannon

unread,
Feb 14, 2014, 7:28:33 PM2/14/14
to mailchimp-...@googlegroups.com
Hey Bohdan!

When it comes to Python a structure is going to be a dictionary (dict).

In this particular case it appears that there are some formatting errors within the subscribe call itself, such as the email struct.

Here's an example to help give you a general idea of what the API is expecting, if you'd like to check it out:

import mailchimp

apikey
= "<my api key>"
m
= mailchimp.Mailchimp(apikey)
list
= m.lists.list()
id
= list["data"][0]["id"]
#webid = list["data"][0]["web_id"]
email
= {"email":"exa...@examples.com"}
m
.lists.subscribe(apikey,id,email)

- Shannon

Bohdan Anderson

unread,
Feb 24, 2014, 11:07:40 AM2/24/14
to mailchimp-...@googlegroups.com
Thank you Shannon for the quick reponce, but I still seem to be getting the same error as before using the example code...  

Traceback (most recent call last):
  File "/Library/WebServer/Documents/Also/Github/kantelberg/emails/mailchimpexample.py", line 9, in <module>
    m.lists.subscribe(apikey,myId,email)
  File "/Library/Python/2.7/site-packages/mailchimp.py", line 2213, in subscribe
    return self.master.call('lists/subscribe', _params)
  File "/Library/Python/2.7/site-packages/mailchimp.py", line 349, in call
    raise self.cast_error(result)
mailchimp.ValidationError: Validation error: {"email":"Please enter a struct\/associative array"}

Colt

unread,
Feb 24, 2014, 11:28:59 AM2/24/14
to mailchimp-...@googlegroups.com
Hey Bohdan!

Thank you for reaching back out!

When it comes to the MailChimp API group we're here to answer questions regarding the MailChimp API directly rather then troubleshoot the code itself. We aren't experts on all of the programming languages out there. When it comes to our example was more of general guidance on what the API itself expects, rather then a hard set working example.The code required can be totally different depending on the wrapper being used. 

That being said from the error you are receiving it doesn't appear the correct information is being passed along in the request to our API. Depending on the wrapper you are using it may be worth referencing the wrapper itself to see what type of parameter it is expecting regarding that particular call.

In the end though the best course of action would be to reach out to a coding community to troubleshoot that code as they will have more of an expertise in a language such as Python in order to help get you going in the right direction.

-Colt
Reply all
Reply to author
Forward
0 new messages