0

I'm using Mailchimp module for user registration and at this page I found a function for registering users programatically:

mailchimp_subscribe (
    $list_id,
    $email,
    array (
        'EMAIL' => $email,
        'FNAME' => $first_name, // fields in your mailchimp list
        'LNAME' => $last_name,
    ),
    false,
    false
)

In my mailchimp account I have defined new field of radio buttons type (field name 'type' with options 'client' and 'expert').

I have 2 questions:

  • How should be the 'type' column in mailchimp_subscribe() function specified?
  • How could be an existing user in mailchimp programatically updated?
1

The key in the array can be MERGEX (where Xth field number in MailChimp) or whatever custom tag name you've set in MailChimp (it shows up as *|TAGNAME|*" in MailChimp field settings) . The MailChimp dropdown user fields aren't like Drupal's (with select fields containing a key/value pair); all it needs is the literal display value of option.

mailchimp_subscribe() eventually calls MailchimpLists::addOrUpdateMember() in its dependent library. Thus, the logic of adding/updating is handled for you in the function.

To put that together in the above code snippet:

mailchimp_subscribe(
    $list_id,
    $email,  //Will add or update $email in $list_id based on subscriber status
    array (
        'EMAIL' => $email,
        'FNAME' => $first_name, // fields in your mailchimp list
        'LNAME' => $last_name,
        // Assuming the 'type' field in MailChimp is your 3rd field 
        'MERGE3' => 'client',
    ),
    false,
    false
);
  • Thanks. I'd like to ask one more question: Is there any drupal function for retrieving list of registered users with their fields values from mailchimp? Cannot find a documentation for this. – Incredible May 3 '16 at 11:06
  • I don't know. Look for a reference to getMembers(), that's the name of the method used in the library. If there's a wrapper function for it, it might reference it. – Shawn Conn May 3 '16 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.