mailchimp-api icon indicating copy to clipboard operation
mailchimp-api copied to clipboard

Adding a subscriber to a group of a list

Open jakepm opened this issue 7 years ago • 3 comments

Firstly, let me say that this wrapper is awesome and an absolute pleasure to use.

I'm struggling to understand how to add a user to a Group that my client has included inside a list.

My understanding is that they have created a 'Group category' under the list that I'm adding the subscriber to. And that 'Group category' has several 'Group names' inside of it. Could you advise how I also add the user to the group category/name?

$MC = new MailChimp('api-key'); $list_id = 'list-id'; $result = $MC->post("lists/$list_id/members", [ 'email_address' => $data['email'], 'status' => 'subscribed', 'merge_fields' => ['FNAME' => $data['fname'], 'LNAME' => $data['sname']], ]);

jakepm avatar Jul 26 '17 16:07 jakepm

In the API they're called interests. You pass the ID of the group (interest) and if you want them included or not. You can use the API playground to find the ID's.

When you are adding a person, you can just specify the groups to put them in, when you are updating them I believe you need to specify all groups and have them true/false depending on what you want.

You can see about group (interests) here. https://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/interests/

and API calls for doing the groups. https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/

$MC = new MailChimp('api-key');
$list_id = 'list-id';
$result = $MC->post("lists/$list_id/members", [
    'email_address' => $data['email'],
    'status' => 'subscribed',
    'merge_fields' => ['FNAME' => $data['fname'], 'LNAME' => $data['sname']],
    'interests' => ['ABCDEFG' => true, 'HIJKLMN' => false],
]);

where ABCDEFG and HIJKLMN are the id for the interest (group).

nfauchelle avatar Aug 13 '17 09:08 nfauchelle

Just in case anyone else stumbles on this while trying to add interests ... the interest ID is a little hard to find, even in the playground. See the last answer in the Stack Exchange for comprehensive instructions ...

https://stackoverflow.com/questions/32559234/add-to-interest-group-using-mailchimp-api-v3

cheesegrits avatar Mar 22 '18 15:03 cheesegrits

This has been very helpful, just spent hours trying to add a member to a group before I stumbled upon this. Thank you very much.

nashlesigon avatar Sep 05 '18 04:09 nashlesigon