PerceptiveMCAPI C# Console App help needed

Jun 9, 2011 at 7:37 PM
Edited Jun 13, 2011 at 1:16 PM

Hello, I need this to work from a console app for a nightly batch job for a client and future clients.

I have used code from the examples and modified it somewhat to get it to almost work. I'm running into issues I cannot solve on my own at this point and need some help.

What's done:

I dragged PerceptiveMCAPI.dll into the bin directory and added a reference to it.

I know how to do the DB lookup no problem and will add that after I get MailChimp sorted,..But I'm having trouble getting the MailChimp portion to stop showing compile errors.

I was following an example that uses 'Lists' but after reviewing this all...

Couldn't I just feed a datareader directly into a dictionary object and skip the 'list' portion? Basically can I just datareader into the 'listbatchsubscribe_method' method below?

It seems redundant to feed a datareader into a list (in Main()), then feed a list into the dictionary object (in listbatchsubscribe_method())...??..

Please advise me of the easiest way to do this. Feel free to modify the code at will.

Here's the error:

Error    1    The type or namespace name 'Subscriber' could not be found (are you missing a using directive or an assembly reference?)    C:\Users\Beau D'Amore\Documents\Console Apps\MailChimpAPI-Csharp\MailChimpAPI-Csharp\Program.cs    91    52    MailChimpAPI-Csharp

This error occurs inside public void listBatchSubscribe_method(List<Subscriber> SubscriberList)  <<=== right here. I have added the reference and it still shows up as an error when building the solution. Please help.


Here's the code:

using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.OleDb;
using System.IO;

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

namespace MailChimpAPI_Csharp
    class Program
        static void Main(string[] args)
                //The following qstring find those who registered
                //but either never purchased or returned/voided/frauded and never re-purchased
                string connectionString = GetConnectionString();
                string queryString =
                    "SELECT DISTINCT Customer.Email, Customer.FirstName, Customer.LastName "+
                    "FROM Customer  " +
                    "WHERE NOT EXISTS " +
                    "(SELECT * FROM Orders  " +
                    "WHERE Customer.CustomerID = Orders.CustomerID AND  " +
                    "(Orders.RefundedOn IS NULL) AND (Orders.VoidedOn IS NULL) AND  " +
                    "(Orders.FraudedOn IS NULL) AND (Orders.AuthorizedOn IS NOT NULL)) AND  " +
                    "Customer.Email <>'' AND  " +
                    "Customer.Email is not null";
                using (OleDbConnection connection =
                           new OleDbConnection(connectionString))
                    OleDbCommand command = connection.CreateCommand();
                    command.CommandText = queryString;


                        OleDbDataReader reader = command.ExecuteReader();

                        //I know the following is all jumbled up.
                        //I was using different source examples and got lost in it all..
                        //it's supposed to match 
                        //public void listBatchSubscribe_method(List<Subscriber> SubscriberList) near the bottom
                        using (reader)
                            System.Collections.Generic.List<MailChimpList> arrObjects = new System.Collections.Generic.List<MailChimpList>();
                            List<MailChimpList> student = new List<MailChimpList>();
                            int customerId = reader.GetOrdinal("customerId ");      //obviously this needs massaging...but how?
                            int CustomerName = reader.GetOrdinal("CustomerName ");  //obviously this needs massaging...but how?

                            while (reader.Read())
                                CustomerEntity obj = new CustomerEntity();
                                obj.customerId = (reader[customerId] != Convert.DBNull) ? reader[customerId].ToString() : null;
                                obj.CustomerName = (reader[CustomerName] != Convert.DBNull) ? reader[CustomerName].ToString() : null;


                        while (reader.Read())
                        //build a list of users from the DB to update in listbatchsubscribe
                    catch (Exception ex)

        //then use this folowing listbatchsubscribe from PerceptiveMCAPI
        // A little more intense request (listBatchSubscribe using Serial/JSON)
        // assumes a collection was created elsewhere from database info
        // with email, email_type, first name, last name, and last_payment

        public 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.apikey = MCAPISettings.default_apikey;
   = "YourListId";
            input.double_optin = false;
            input.replace_interests = true;
            input.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_TYPE", sub_rec.email_type);
                entry.Add("FNAME", sub_rec.first_name);
                entry.Add("LNAME", sub_rec.last_name);
                DateTime next_payment = sub_rec.last_payment.AddMonths(1);
                entry.Add("NEXTPAY", next_payment);
            input.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

        static private string GetConnectionString()
            // To avoid storing the connection string in your code,
            // you can retrieve it from a configuration file.
            // Assumes Northwind.mdb is located in the c:\Data folder.

            //I will change this to use an external text file later================
            //TESTING ONLY!!!!!!!!!!!1=============================================
            return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
                + "c:\\Data\\Northwind.mdb;User Id=admin;Password=;";


Jun 10, 2011 at 5:07 PM

bumpity bump bump...

Jun 13, 2011 at 1:12 PM

Nobody wants to touch this question?.. I really need help folks...

Jul 6, 2011 at 10:42 PM

can you tell me how you created the reference?

im trying to create an console app too, but after adding a reference to the dll as usual, but when i build in visual studio i get an error saying that i cant referense since the .dll has depencency of system.web.extensions...

Feb 16, 2012 at 9:51 PM

In VS2010, go to Project|Properties.  On the Application tab, check the target framework.  You likely have ".NET Framework 4 Client Profile" selected.  Change this to ".NET Framework 4" and you should be good to go.