Add to interest group using Mailchimp API v3
Asked Answered
B

3

22

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?

Brassy answered 14/9, 2015 at 7:24 Comment(5)
Ok so I did a get which showed me all the members and exposed an alphanumeric id for each group. No idea how you would get it this using the MailChimp console.Brassy
You can get the API interest IDs from /lists/<id>/interest-categories/<id>/interestsTuraco
Ahh cool!! Thanks TooMuchPete!Brassy
I was able to get to the group/interest ids through MailChimp's API Playground pretty easily.Autotruck
This is soo bad comparing to v1 and v2. Now we need to request the names from each category individually!Concussion
A
30

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

Aceous answered 30/11, 2016 at 6:15 Comment(1)
I think I vote your answer because I need to find the interest ID :) ... ThanksFog
J
19

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.

Juniper answered 4/3, 2016 at 6:9 Comment(3)
Urghh, we were just creating an interest title, not an actual group! Doh! @user3029992, mark this as the correct answer please.Bayou
This should be marked as the correct answer. So glad I stumbled across this. About pulled all my hair out.Moynahan
Thank you so much for this! MailChimp really should update their documentation to clarify this.Nitin
P
1

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) }
Potboiler answered 31/5, 2018 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.