Add to interest group using Mailchimp API v3

user3029992 picture user3029992 · Sep 14, 2015 · Viewed 15.3k times · Source

I'm using this MailChimp api v3 wrapper https://github.com/drewm/mailchimp-api/tree/api-v3

Using the example I can add an email to my list but cannot add it to one of my interest groups.

This is the example code:

$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');
    $result = $MailChimp->post('lists/b1234346/members', array(
                'email_address'     => '[email protected]',
                'status'            => 'subscribed',
                'merge_fields'      => array('FNAME'=>'Davy', 'LNAME'=>'Jones'),
                'interests'         => array( '2s3a384h' => true )
                )); 
print_r($result);

My understanding is the key in that array entry for interests is the ID of the group. I created a group in MailChimp, which has a group title and group names. I can see an id when I hover over the group title edit button, and also the group name edit button. If I hover over the "0 subscribers" for a group name I can see that same id and a group_id. I've tried both values and I get this error:

Array ( [type] => http://kb.mailchimp.com/api/error-docs/400-invalid-resource [title] => Invalid Resource [status] => 400 [detail] => Invalid interest ID: '39561'. [instance] => 12c1ab46-a0b5-4014-8107-08cfa97a9a94 )

I've googled and still can't find the answer. Any help?

Answer

Jannie Theunissen picture Jannie Theunissen · Nov 30, 2016

You can get the Id of the specific interest option not the group id, by going to the playground

Then you navigate to your list and group:

navigate to list and group in playground

When you click on the name of the interest option it will show the option meta data, including it's id:

enter image description here