Get list of subscribers and add a new subscriber

Mar 9, 2011 at 9:55 AM

Good evening David,

Thank you this API. I've been digging this discussions and google group to look for how I can get a list of subscriber from MailChimp and add a new subscriber to MailChimp. I've been reading the documentation and some posts here and there. I managed to get some result back from the API. The code below will give me a list of campaigns and their info.

Dim input As listBatchSubscribeInput = New listBatchSubscribeInput()
input.api_Validate = False
Input.api_AccessType = EnumValues.AccessType.Serial
Input.api_OutputType = EnumValues.OutputType.JSON

Dim campInput As campaignsInput = New campaignsInput
Dim camp As campaigns = New campaigns(campInput)

Dim campOutput As campaignsOutput = camp.Execute()

For Each result As campaignsResults In campOutput.result
Response.Write("ID: " & result.id & " " & "Name " & result.title & ", Analytics Tag: " & result.analytics_tag & "<br/>")
Next

If anyone knows how to get a list of subscribers (Email, First Name, Last Name, even though what I really need is Email), please help me out. Also, please show me how to add a new subscriber.

I'm new to this API.

Thank you so much.

 

 

Mar 9, 2011 at 10:24 AM

I tried the code below but I didn't get anything:

Is there anything wrong with that code block?

Dim lmi As listMembersInput = New listMembersInput()
lmi.api_Validate = False
lmi.api_AccessType = EnumValues.AccessType.Serial
lmi.api_OutputType = EnumValues.OutputType.JSON

Dim listIn As listMembersInput = New listMembersInput
Dim listMem As listMembers = New listMembers(listIn)
Dim listOut As listMembersOutput = listMem.Execute

For Each mem As listMembersResults In listOut.result

Response.Write("<br/> --- " & mem.email & " -- " & mem.timestamp & "<br/>")

Next

Thank you.

Coordinator
Mar 9, 2011 at 1:05 PM
narazana wrote:

Dim input As listBatchSubscribeInput = New listBatchSubscribeInput()

input.api_Validate = False
Input.api_AccessType = EnumValues.AccessType.Serial
Input.api_OutputType = EnumValues.OutputType.JSON

Worthless - what does a batch subscribe input class have to do with campaigns & directives are assigned after the input definition so they are not doing any good for the campaignsInput class either

Coordinator
Mar 9, 2011 at 1:17 PM

--------------------------------------------------------------- below is worthless, never used since you create another input class and use that instead 

Dim lmi As listMembersInput = New listMembersInput()
lmi.api_Validate = False
lmi.api_AccessType = EnumValues.AccessType.Serial
lmi.api_OutputType = EnumValues.OutputType.JSON

 

-----------------------------------------------------------------------

below -- sure you created the classes, but you never assigned any parameters - how is the api supposed to know what list you want members for?
the only reason your campaigns() api call works was that it didn't need any parameters other than the apikey 

Dim listIn As listMembersInput = New listMembersInput
Dim listMem As listMembers = New listMembers(listIn)
Dim listOut As listMembersOutput = listMem.Execute

------------------------------------------------------------------------

My recommendation is that you read the MailChimp documentation (and mine) and
spend some serious think time. 

Mar 9, 2011 at 5:48 PM

Thank you for your prompt reply. :D

I managed to get list of subscribers and add news subscriber to the list.

This is how I add new subscriber:

Public Sub AddSubscriber(ByVal emailAddress As String)

Dim input As listSubscribeInput = New listSubscribeInput()
input.api_Validate = True
input.api_AccessType = EnumValues.AccessType.Serial
input.api_OutputType = EnumValues.OutputType.JSON
input.parms.apikey = apikey
input.parms.id = listId
input.parms.send_welcome = True
input.parms.update_existing = True
input.parms.email_address = emailAddress

Dim cmd As listSubscribe = New listSubscribe(input)
Dim output As listSubscribeOutput = cmd.Execute

End Sub

This is how I get the list of the subscribers:

Public Sub GetListOfSubscriber()

Dim listIn As listMembersInput = New listMembersInput(apikey, listId, EnumValues.listMembers_status.subscribed, 0, 100)
Dim listMem As listMembers = New listMembers(listIn)
Dim listOut = listMem.Execute

For Each rs In listOut.result
Response.Write(rs.email & "<br/>")
Next

End Sub

But I'm still having problem with listBatchSubscribe. I cannot figure out why it won't add subscribers. Here's my code:

Public Sub BatchAddSubscriber()

Dim input As listBatchSubscribeInput = New listBatchSubscribeInput()
'directives override
input.api_Validate = True
input.api_AccessType = EnumValues.AccessType.Serial
input.api_OutputType = EnumValues.OutputType.JSON
' method parameters
input.parms.apikey = apikey
input.parms.id = listId
input.parms.double_optin = True
input.parms.replace_interests = True
input.parms.update_existing = True
'
Dim batch As List(Of Dictionary(Of String, Object)) = New List(Of Dictionary(Of String, Object))

Dim emailList() As String = {"example1@abc.com", "example2@abc.com"}

For i = 0 To emailList.Length - 1 Step 1

Dim entry As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
entry.Add("EMAIL", emailList(i))
entry.Add("EMAIL_TYPE", "html")
batch.Add(entry)
Next

input.parms.batch = batch
' execution
Dim cmd As listBatchSubscribe = New listBatchSubscribe(input)
Dim output As listBatchSubscribeOutput = cmd.Execute()


 End Sub

Thanks for any input.

Jun 13, 2011 at 6:01 PM

Did you ever fix listbatchsubscribe? I need help.

Oct 15, 2011 at 7:16 AM

Hi narazana,

Thank you for the code.

It helped me lot!

Suhani.

May 19, 2012 at 7:00 PM

For anyone still struggling, with subscribing a user using the PerceptiveMCAPI, i've written a step-by-step walk through on my blog, with C# and VB code.

http://mattjroden.com/post/2012/05/19/Mailchimp-Subscribe-form-in-ASPnet-VB-C.aspx

Hope it helps!

 

p.s. Don't forget to like/comment/share if you find it helpful!

Jul 12, 2013 at 9:02 AM
Edited Jul 12, 2013 at 9:07 AM
How to Get list of subscribers from mail chimp list using asp .net C#

i have subscribe or add email in Mail Chimp List


public class Subscriber
{
public object first_name;
public object last_name;
public object email_type;
public object email { get; set; }
}

-------------------------------------calling function -------------------
List<Subscriber> SubscriberList = new List<Subscriber>();
    SubscriberList.Add(new Subscriber {  email_type = ss, first_name = user, last_name = lname });
    listBatchSubscribe_method(SubscriberList);
------------------------------------------------------------0Function 0 ---------------------------------
public void listBatchSubscribe_method(List<Subscriber> SubscriberList)
{
    listBatchSubscribeInput input = new listBatchSubscribeInput();
    input.api_AccessType = EnumValues.AccessType.Serial;       // access
    input.api_OutputType = EnumValues.OutputType.JSON;       // output
    //  input.api_MethodType = MethodType;        // method
    //   input.api_EncodeRequest = EncodeRequest;  // encode
    input.api_Validate = false;     // validate
    input.parms.apikey = "c5efhdsfyusdfdshfjdshfkdshfhdsfd1cafsdfdsfdsf";
    input.parms.id = "6d4asfdasfdsfds";
    input.parms.double_optin = false;
    input.parms.replace_interests = MCAPISettings.default_listSubscribe_replace_interests;
    input.parms.update_existing = true;
    //
    List<Dictionary<string, object>> batch = new List<Dictionary<string, object>>();
    foreach (Subscriber sub_rec in SubscriberList)
    {
        Dictionary<string, object> entry = new Dictionary<string, object>();
        entry.Add("EMAIL", sub_rec.email);
        entry.Add("EMAIL_TYPE", sub_rec.email_type);
        entry.Add("NAME", sub_rec.first_name);
        entry.Add("LASTNAME", sub_rec.last_name);
        //   DateTime next_payment = sub_rec.last_payment.AddMonths(1);
     //   entry.Add("NEXTPAY", next_payment);
        batch.Add(entry);
    }
    input.parms.batch = batch;
    // execution
    listBatchSubscribe cmd = new listBatchSubscribe(input);
    listBatchSubscribeOutput output = cmd.Execute();
    // output, format with user control
    if (output.api_ErrorMessages.Count > 0)
    {
        lmess.Text = "Network Probelms in Mailchimp site !!!";
    }
    else
    {
        lmess.Text = "Thanks For Subscribing!!!";
    }
}
Jul 12, 2013 at 9:08 AM
How to Get list only emai_id of subscribers from mail chimp list using asp .net C#