Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all members from the mailing list using MailChimp API 3.0

http://kb.mailchimp.com/api/resources/lists/members/lists-members-collection

Using this resource we can obtain only first 10 members. How to get all?

like image 397
graceman9 Avatar asked Aug 21 '15 14:08

graceman9


2 Answers

The answer is quite simple - use offset and count parameters in URL query:

https://us10.api.mailchimp.com/3.0/lists/b5b5fdc2fa/members?offset=150&count=10

Finally I found PHP API client for MailChimp API v3: https://github.com/pacely/mailchimp-api-v3

And official docs about pagination.. I missed it before :( http://kb.mailchimp.com/api/article/api-3-overview

like image 60
graceman9 Avatar answered Sep 20 '22 09:09

graceman9


I stumbled on this one while researching a way to get all list members in MC API 3.0 as well. I noticed that there were some comments on the API timing out when trying to get all list members on one page. I also encountered this at first but was able to overcome it by limiting the fields in the result by using the 'fields' param. My code is for a mass deleter so all I really needed was the ID of each member to put together a batch delete request. Here's how my fetch request looks (psuedo-code):

$total_members = $result['total_items'];//get number of members in list via previous request
https://usXX.api.mailchimp.com/3.0/lists/foobarx/members?fields=members.id&count=total_members

This way I'm able to fetch over 15,000 subscribers on one page without error.

like image 43
Tate Harmann Avatar answered Sep 17 '22 09:09

Tate Harmann