Closed alan-parry closed 6 years ago
Hi @alan-parry 👋 ,
thanks for you question.
In fact there are several overloaded methods to create a member for a list.
In your case only the second option is valid, because the the first does not provide the necessary parameters and the third one only works if you already have an Member object which can only be retrieved from the API. I see that there needs to be some better naming and documentation for the methods. I will file an issue for that. But for now we stick to the 2. option and you can do the following.
With the 2. option you can declare values for the so called MergeFields
which you can find in your MailChimp List settings under "Settings" -> "List fields and |MERGE| tags". Here you need to choose the tags in the Put this tag in your content:
column as keys into a HashMap in Java and the value is the value to which you want to set the merge field. For example
MailChimpList mailChimpSubscriptionList = con.getList(mailChimpList.getId());
List mailChimpMembers = mailChimpSubscriptionList.getMembers(0,0);
HashMap<String, Object> mergeFields = new HashMap<>();
mergeFields.put("FNAME", "John"); // merge field for the first name of a member
mergeFields.put("LNAME", "Smith"); // merge field for the first name of a member
list.addMember(MemberStatus.SUBSCRIBED , emailAddress, mergeFields);
With that you can add members with a first and last name. Let me know if this helped you :)
Thanks, this really helped! I'd seen the merge fields but didnt understand what they did. Thanks to this I'be got it working so yes having this documented would be a big help for others I'm sure. Cheers :)
Your are welcome, I am glad that my description helped you.
I try to document this as soon as possible.
I'm trying to set the firstname/lastname of members I am adding to a mailchimp list. Is that possible using this API? I can't see how it can be done.
MailChimpList mailChimpSubscriptionList = con.getList(mailChimpList.getId()); List mailChimpMembers = mailChimpSubscriptionList.getMembers(0,0);
mailChimpSubscriptionList.addMember(MemberStatus.SUBSCRIBED, emailAddres);