简体   繁体   中英

Mailchimp API with Groupings

I need to add a MailChimp subscriber to a specific grouping. I have no issue getting the subscriber subscribed, but can't seem to get them into a specific grouping.

This is what I have:

// ENTER INTO MAILCHIMP

$newsletter =  $_POST['newsletter'];
$newsletter = 'yes';                 

if ($newsletter = "yes") {
    $MailChimp = new \Drewm\MailChimp('api');
    $result = $MailChimp->call('lists/subscribe', 
                array(
                        'id' => 'listnumber',
                        'email' => array('email'=> $_POST['usersEmail']),
                        'merge_vars' => array(
                                            'FNAME'=>$_POST['usersName'], 'LNAME'=>$_POST['usersLastName'],
                                            'groupings' => array(
                                                                'id' => 494281,
                                                                array(
                                                                    'name'=>'KeepBoard',
                                                                    'groups' => 'KeepBoardUsers'
                                                                )
                                                            )
                                            ),
                                            'double_optin'      => false,
                                            'update_existing'   => true,
                                            'replace_interests' => false,
                                            'send_welcome'      => false
                    ));
    print_r($result);
} 

Also I am not entirely sure where to grab the listing id. I can't seem to find documentation. I worked off the URL. But I don't think that is right because that is the id for all groupings.

For those that have this problem this was the issue. The groups have to be an array, even for a single group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM