Jun 17, 2011 at 8:43 PM
Edited Jun 17, 2011 at 8:47 PM

I just got listbatchsubscribe working in my C# console app.

I need to know how to do a listbatchUNsubscribe (or equivalent) in C#...or VB.NET is fine as well. But the PHP examples I see around don't help.

Can you help me?

Here's what I have so far that works (except for the listbatchUnsubscribe portion, obviously...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.IO;

using System.Diagnostics;

using PerceptiveMCAPI.Types;
using PerceptiveMCAPI;
using PerceptiveMCAPI.Methods;

namespace MailChimpTest
    class Program
        static void Main(string[] args)

                //The following queryString finsd those who registered
                //but either never purchased or returned/voided/frauded and never re-purchased
                string QueryStringToBeSubscribed = ConfigurationManager.AppSettings["QueryStringToBeSubscribed"].ToString();
                //The follwing querystring is used to remove those who purchased from the list.
                string QueryStringToBeRemoved = ConfigurationManager.AppSettings["QueryStringToBeRemoved"].ToString();

                string connectionString = GetConnectionStringByName("WebimaxMailChimpAPIConnectionString");

                using (OleDbConnection connection =
                           new OleDbConnection(connectionString))
                    OleDbCommand command = connection.CreateCommand();
                    command.CommandText = QueryStringToBeSubscribed;


                        OleDbDataReader reader = command.ExecuteReader();

                        List<Subscriber> MyList = new List<Subscriber>();
                        while (reader.Read())
                            //build a list of users into 'MyList' from the DB to update in listbatchsubscribe

                            Subscriber sub = new Subscriber(reader["EMAIL"].ToString(), "0", reader["FNAME"].ToString(), reader["LNAME"].ToString());


                     catch (Exception ex)
                        string sSource;
                        string sLog;
                        string sEvent;

                        sSource = "MailChimpAPISource";
                        sLog = "MailChimpAPILog";
                        sEvent = "Error:" + ex.Message.ToString();

                        if (!EventLog.SourceExists(sSource))
                            EventLog.CreateEventSource(sSource, sLog);

                        EventLog.WriteEntry(sSource, sEvent);
                        EventLog.WriteEntry(sSource, sEvent,
                        EventLogEntryType.Warning, 234);

        public static void listBatchSubscribe_method(List<Subscriber> SubscriberList)
            listBatchSubscribeInput input = new listBatchSubscribeInput();
            // any directive overrides
            input.api_Validate = true;
            input.api_AccessType = EnumValues.AccessType.Serial;
            input.api_OutputType = EnumValues.OutputType.JSON;
            // method parameters
            input.parms.apikey = MCAPISettings.default_apikey;

            //Change this to client's list name when live=============================
   = ConfigurationManager.AppSettings["MailChimpListID"].ToString();

            input.parms.double_optin = false;
            input.parms.replace_interests = true;
            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("FNAME", sub_rec.FNAME);
                entry.Add("LNAME", sub_rec.LNAME);
                //DateTime next_payment = sub_rec.LAST_PAYMENT.AddMonths(1);
                //entry.Add("NEXTPAY", next_payment);
            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)
                //showResults(output.api_Request, output.api_Response, // raw data
                //output.api_ErrorMessages, output.api_ValidatorMessages); // & errors

                string sSource;
                string sLog;
                string sEvent;

                sSource = "MailChimpAPISource";
                sLog = "MailChimpAPILog";
                //sEvent = "Error:" + ex.Message.ToString();

                sEvent = "MailChimpAPI-Error:" + output.api_ValidatorMessages.ToString();

                if (!EventLog.SourceExists(sSource))
                    EventLog.CreateEventSource(sSource, sLog);

                EventLog.WriteEntry(sSource, sEvent);
                EventLog.WriteEntry(sSource, sEvent,
                EventLogEntryType.Warning, 234);
                //SEND an email with who was subscribed======
                //log usage==================================


       // listBatchUnsubscribe(string apikey, string id, array emails, boolean delete_member, boolean send_goodbye, boolean send_notify)

        public static void listBatchUnSubscribe_method(Array UnSubscribers)

            listBatchUnSubscribeInput input = new listBatchSubscribeInput();

        public class Subscriber
            public string EMAIL;
            public string EMAIL_TYPE;
            public string FNAME;
            public string LNAME;
            //public DateTime LAST_PAYMENT;

            public Subscriber(string sEmail, string sEMAIL_TYPE, string sFNAME, string sLNAME)/*, DateTime sLAST_PAYMENT*/
                EMAIL = sEmail;
                EMAIL_TYPE = sEMAIL_TYPE;
                FNAME = sFNAME;
                LNAME = sLNAME;
                //LAST_PAYMENT = sLAST_PAYMENT;


        // Retrieves a connection string by name.
        // Returns null if the name is not found.
        static string GetConnectionStringByName(string name)
            // Assume failure.
            string returnValue = null;

            // Look for the name in the connectionStrings section.
            ConnectionStringSettings settings =

            // If found, return the connection string.
            if (settings != null)
                returnValue = settings.ConnectionString;

            return returnValue;


Jul 5, 2011 at 4:42 PM


I see you've  been able to get the method for batch subscription working!

I'm also working on a console application that's supposed to run overnight and update my mailing list.

I have a question, I've been able to find the reason why the reference wasn't working, which was my first problem with this API, on another forum (I think it was one of your posts that solved my issues actually). But now I have the BatchSub Method coded and ready to go I can't seem to get it to work.


        Dim input As New listBatchSubscribeInput

So when I hit the first line (shown down there) I get a "ConfigurationErrorsException" and I have pretty much no clue as to why. The "listBatchSubscribeInput" Class is detected without a itch while I'm coding, so I can pretty much rule out the Reference problem I was having earlier today.

As far as my app.config file goes I pretty much copied what I found on another forum that was working for someone and changed the APIKey to mine.

Any help would be greatly appreciated !