Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add to interest group using Mailchimp API v3

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?

like image 481
user3029992 Avatar asked Sep 14 '15 07:09

user3029992


People also ask

How do I add a subscriber to my Mailchimp API?

Create Mailchimp API keysGo to mailchimp select account, you will find extras dropdown. Select API keys and in the bottom left you will find a button Create A Key . Click on it and your api key is created. You have to copy the API Key under the API Key header.

How do I find my interest ID in Mailchimp?

The Playground is a UI into the API and you can drill down using the Subresources into -> lists -> interest-categories -> interests. Then choose the Response view and it will show the payload of the response that contains the id's you are looking for.


3 Answers

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

like image 197
Jannie Theunissen Avatar answered Sep 22 '22 09:09

Jannie Theunissen


Interests are (can be? must be?) grouped under interest-categories, but you only need the ID of the interest itself, not the ID of the interest-category when setting it for the user.

Your error may be from using the interest-category ID instead of the specific interest ID.

like image 36
Bob Ray Avatar answered Sep 21 '22 09:09

Bob Ray


A quick and dirty way to capture all of the Interest IDs...

$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')
                )); 
print_r($result);

Your print_r after not specifying the "interests" key in the post should provide you with an interests array with the IDs telling you they are all marked as false.

["interests"]=> array(7) { ["258ad948a1"]=> bool(false) ["8e30162ec8"]=> bool(false) ["f2f79df229"]=> bool(false) ["b4e2f6effc"]=> bool(false) ["4fb0927fef"]=> bool(false) ["f2d1e06470"]=> bool(false) ["9f6c7c4db2"]=> bool(false) }
like image 24
Christopher Johnston Avatar answered Sep 20 '22 09:09

Christopher Johnston