Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add users to interest group via MailChimp API v2.0

Tags:

php

api

mailchimp

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) "[email protected]"
}

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?

like image 476
Sacha Avatar asked Aug 26 '13 18:08

Sacha


1 Answers

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.

like image 78
Sacha Avatar answered Oct 27 '22 22:10

Sacha