0
votes

I have three list with thousands of members. I'm creating a little stats module for the admins of my Django site. The three lists have an extra custom field called Language (es_ES, en_CA, fr_CM,...). I want to show the count of members of each list filtered by 'this' Language.

Browsing the Mailchimp API I can see that it's possible to create a saved segment with "filter" options (filtering by Language in my case), but when you get via API those segments you can't get the count of members for the segment. It's not in the return value of Mailchimp. It's possible to get it with a static segment, but not with a saved one.

Any help to get the count for a filtered and saved segment?

You can check the "list related methods" of the MChimp API here: https://apidocs.mailchimp.com/api/2.0/#lists-methods

1

1 Answers

0
votes

I'm trying to solve the same problem myself.

I believe this can be done relatively easily with the segment-test method. All you have to do is pass in (besides your API key), parameters list_id, and (inside an options object) saved_segment_id. The call will return the total number of subscribers that match the saved segment. For example:

curl -X POST https://us1.api.mailchimp.com/2.0/lists/segment-test.json --data '{"apikey":"MYAPIKEY","list_id":"MYLISTID","options":{"saved_segment_id":MYSEGMENTID}}'

To get the segment ID for all the saved segments in your list, you can first call the segments method, like this:

curl -X POST https://us1.api.mailchimp.com/2.0/lists/segments.json --data '{"apikey":"MYAPIKEY","id":"MYLISTID"}'

Note that the list ID is passed as "id" in the segments method, but as "list_id" in the segment-test method.