7

I want to add a subscriber to an interest group via the MailChimp API.

This is my $merge_vars array:

$merge_vars = array(
    'GROUPINGS' => array(
        0 => array(
            'id' => 17385, // The group list ID
            'groups' => "Test 123", // A test group, that does exist
        )
    )
);              

and this is how I'm updating the member:

$update = $mc->lists->updateMember(self::$mainListID, $email, $merge_vars);

Here's a var_dump($merge_vars):

array(1) {
  ["GROUPINGS"]=>
  array(1) {
    [0]=>
    array(2) {
      ["id"]=>
      int(17385)
      ["groups"]=>
      string(8) "Test 123"
    }
  }
}

and $email is a struct, here's $var_dump($email):

array(1) {
  ["email"]=>
  string(11) "my@mail.com"
}

I'm about to be driven to distraction, because the API doesn't return an error, everything seems to go smoothly, except for the big problem of the user not being added to the list.

I've looked at this question which helped me get so far, but the version of the API it uses is 1.3 and that might have something to do with it.

What am I doing wrong?

Community
  • 1
  • 1
Sacha
  • 559
  • 7
  • 23

3 Answers3

15

Well, I figured it out.

Although I could have sworn I'd already tried it this way... the groups have to be an array, even for a single group.

My code now:

$merge_vars = array(
    'GROUPINGS'=> array(
        array(
            'id' => 17385,
            'groups' => array($post['listName'])
        )
    )
);

$mc->lists->updateMember(self::$mainListID, $email, $merge_vars);

Works perfectly.

Niklas Modess
  • 2,521
  • 1
  • 20
  • 34
Sacha
  • 559
  • 7
  • 23
  • I am stuck with this too - but it looks to me like your question already had the groups as an array, with a single group inside. – Paul Feb 20 '14 at 06:00
  • 1
    Aah. Ok, the list of group entries themselves should not be an array, they should be a comma delimited list. I am surprised this worked. – Paul Feb 21 '14 at 01:59
  • Which version of the API are you using? It may have changed. – Sacha Feb 21 '14 at 11:19
  • Thanks - you are right, I was using an old api - 1.3. – Paul Feb 23 '14 at 22:40
  • You should look into updating to the latest API, v2.0. I just updated a plugin that was using 1.3 to 2.0. It wasn't too difficult. It just involved updating the wrapper class we were using and re-writing a few functions. – EHerman Feb 26 '14 at 15:57
  • $merge_vars = array( 'GROUPINGS'=> array( array( 'id' => 4541, 'groups' => "$95 - Silver White, $95 - Gold Face" ) ) ); $subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['email']) ), array( 'ADDRESS' => implode(' ',$address)), $merge_vars ); What is wrong here? – Thiyagarajan Veluchamy May 08 '15 at 06:20
3

For me works using name instead of id group.

$merge_vars = array(
    'groupings'=> array(
        array(
            'name' => 'Group Name',
            'groups' => array('Group item name')
        )
    )
);
1

Agree with @Sanaco

add this example for more checkboxes

$option1=$_POST['xxxx'];
$option2=$_POST['xxxx'];
$option3=$_POST['xxxx'];

'GROUPINGS'=> array(
                            array(
                                'id' => 123456,
                                'groups' => array($option1, $option2, $option3)
                            )
                        )
metalbox
  • 302
  • 4
  • 17