Reputation: 55
I'm trying to download all members of a list(there are more than 50000) but I can't find no method to do that across the MailChimp API. On the other hand, I've tried to use the "GetAllMembersForList" method as below but it doesn't get all of them(he gets only 600).
Can anyone let me know if there is other way to download those members list?
public List<string> GetListMembers(string membersList)
{
ListResult lists = mc.GetLists();
List<string> li = new List<string>();
foreach(var list in lists.Data)
{
if (list.Name == membersList)
{
MembersResult res;
for (int i = 0; i <= list.Stats.MemberCount; i = i + 100)
{
res = new MembersResult();
res = mc.GetAllMembersForList(list.Id, "subscribed", i, 100);
foreach (var member in res.Data)
li.Add(member.Email);
}
break;
}
}
return li;
}
Upvotes: 1
Views: 1203
Reputation: 55
I've finally found by myself the solution. I found out here https://apidocs.mailchimp.com/export/1.0/list.func.php and I implemented something like below. I am completely sure that someone can improve this but it is the thing that I needed at the time.
Here is the code if someone wants to implement:
public List<string> GetListMembers(string membersList, string status, string since = "")
{
List<string> li = new List<string>();
//to see what does <dc> means? follow this link https://apidocs.mailchimp.com/api/rtfm/
string linkPage = @"http://<dc>.api.mailchimp.com/export/1.0/list/?apikey={0}&id={1}&status={2}{3}";
ListInfo list = mc.GetLists().Data.Where(x => x.Name == membersList).FirstOrDefault();
linkPage = string.Format(linkPage, conectionMailChimp, list.Id, status, !string.IsNullOrEmpty(since) ? "&since=" + since : string.Empty);
WebClient wc = new WebClient();
string text = wc.DownloadString(linkPage);
text = text.Replace("\"", "");
string[] res = text.Split(new[] { "]\n[" }, StringSplitOptions.None);
for (int i = 1; i < res.Length; i++)
li.Add(res[i].Split(new[] { "," }, StringSplitOptions.None)[0].ToString());
return li;
}
Upvotes: 1
Reputation: 4643
To get all of the members in one call (which is seldom actually necessary), you can use the Export API. Otherwise, your best bet is to use the pagination features and download 600 at a time.
Upvotes: 0
Reputation: 552
I think it is because of api throttling / restrictions. But you can ask support for help instead. https://apidocs.mailchimp.com/help/
Upvotes: 1