Add users to interest group via MailChimp API v2.0

只谈情不闲聊 提交于 2019-12-09 11:42:47

问题


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?


回答1:


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.




回答2:


For me works using name instead of id group.

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



回答3:


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)
                            )
                        )


来源:https://stackoverflow.com/questions/18450896/add-users-to-interest-group-via-mailchimp-api-v2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!