1

Anyone know what the proper endpoint is to get all interest groups for a list in Mailchimp's 3.0 API? The only documentation I can find is here: https://github.com/mailchimp/APIv3-examples/wiki/Resources

When I attempt to use /3.0/lists/{list_id}/interest-groupings as mentioned I get the following response:

Class Object ( [type] => http://kb.mailchimp.com/api/error-docs/404-resource-not-found [title] => Resource Not Found [status] => 404 [detail] => The resource 'InterestGroupings_Collection' could not be found. [instance] => )

Requested url looks like this: https://DATA_CENTER.api.mailchimp.com/3.0/lists/LIST_ID/interest-groupings?apikey=API_KEY

I clearly do not have the proper endpoint but thought I would ask as I found the answer to my other issue here on SO.

Community
  • 1
  • 1
Jeremiah Prummer
  • 182
  • 4
  • 18

2 Answers2

4

Though it's an old question, I am posting this answer as the selected answer works no more. The suggested 'API Playground' has been discontinued by MailChimp.

I am using simple CURL commands. You can implement CURL in the language you are working on. Note that ${dc} in CURL commands to be replaced by your MailChimp server prefix.

  1. To do this, first you need to fetch/check the id of the list:
curl -X GET \
  'https://${dc}.api.mailchimp.com/3.0/lists?fields=<SOME_ARRAY_VALUE>&exclude_fields=<SOME_ARRAY_VALUE>&count=10&offset=0&before_date_created=<SOME_STRING_VALUE>&since_date_created=<SOME_STRING_VALUE>&before_campaign_last_sent=<SOME_STRING_VALUE>&since_campaign_last_sent=<SOME_STRING_VALUE>&email=<SOME_STRING_VALUE>&sort_field=<SOME_STRING_VALUE>&sort_dir=<SOME_STRING_VALUE>&has_ecommerce_store=<SOME_BOOLEAN_VALUE>' \
  --user "anystring:${apikey}"'
  1. Once you get the designated ID ({list_id}) from the above output, fetch the interest categories:
curl -X GET \
  'https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/interest-categories?fields=<SOME_ARRAY_VALUE>&exclude_fields=<SOME_ARRAY_VALUE>&count=10&offset=0&type=<SOME_STRING_VALUE>' \
  --user "anystring:${apikey}"'
  1. Note {interest_category_id} from the above output. Finally to get the interest details, use:
curl -X GET \
  'https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/interest-categories/{interest_category_id}/interests?fields=<SOME_ARRAY_VALUE>&exclude_fields=<SOME_ARRAY_VALUE>&count=10&offset=0' \
  --user "anystring:${apikey}"'

A sample PHP function (for Step 3 only) will be as:

function mailchimp_findgrpids()
{
    $mcurl = 'https://'.MAILCHIMP_SERVER_PREFIX.'.api.mailchimp.com/3.0/lists/'.MAILCHIMP_LIST.'/interest-categories/'.MAILCHIMP_INTEREST_CAT.'/interests';
        
    $ch = curl_init($mcurl);

    curl_setopt($ch, CURLOPT_USERPWD, 'user:' . MAILCHIMP_API_KEY);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $result = curl_exec($ch);
    echo $result;
    curl_close($ch);
}
sariDon
  • 7,782
  • 2
  • 16
  • 27
  • 1
    Thanks for the update! Super helpful, even for a 4 year old question. :) – Jeremiah Prummer Jun 19 '21 at 04:08
  • 1
    I signed in to thank you for this — I was ripping my hair out for the longest time trying to figure out how to add a subscriber to a specific "group", but your breakdown of LIST_ID to INTEREST_CATEGORY_ID to INTEREST_ID was exactly what I needed. Many thanks! – trextomcat Mar 22 '23 at 21:36
2

You're looking at severely outdated docs from the beta -- you'd be better off checking out the API Playground, but the endpoint you're looking for is interest-categories.

TooMuchPete
  • 4,583
  • 2
  • 17
  • 21