WCF REST Starter Kit to Constant Contact Sample Application

I’ve had a few requests to get more details on how I used the WCF REST Starter Kit to integrate with the Constant Contact AtomPub API (posted here). It’s shamefully simple but here it is. If you are not satisfied I will give you your money back.

Requires:

Download Sample App

Notes:

  • Update the app.config with your account settings from Constant Contact.
  • Sample is using Http Digest for authentication. If there is interest I can update for OAuth.
using System;
using System.Configuration;
using System.Collections.Generic;
using Freemind.Domain.Email;

namespace Freemind.ConstantContactSample
{
   class Program
   {
      static void Main(string[] args)
      {
         try
         {
            Console.WriteLine("Begin loading Contact Lists");

            // Connect and list Contact Lists
            ContactListProvider provider = new ContactListProvider(
               ConfigurationManager.AppSettings["ConstantContactAccountName"],
               ConfigurationManager.AppSettings["ConstantContactPassword"]);

            List lists = provider.GetContactLists();

            if (lists != null)
            {
               foreach (ContactList list in lists)
               {
                  Console.WriteLine("  list:{0} id:{1}", list.Name, list.id);
               }
            }

            Console.WriteLine("Completed loading Contact Lists");
            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
         }
         catch (Exception ex)
         {
            Console.WriteLine("Error: {0}",ex.Message);
         }
      }
   }
}
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • TwitThis

3 Responses to “WCF REST Starter Kit to Constant Contact Sample Application”

  1. james Says:

    Constant Contact removed support for Digest authentication. Update the GetLoginCredentials() method to use Basic auth. More information here: http://developer.constantcontact.com/doc/authenticationBasic

  2. David Vasquez Says:

    As strict as the T&C for API access is, how are you able to perform list additions on fewer than 25 contacts at a time. The docs recommend using 25 contacts as the threshold to begin using activities (ContactProvider.SynchronizeContacts).

    Would it be worth while to add Contact List support to the Contact class in order to add less than 25 at a time? I’d hate to lose my API access because I wasn’t following the rules. Have you run into any problems with their recommended threshold?

    Great work, by the way. Condensed and cleaned up my work considerably.

  3. james Says:

    Glad to hear it was helpful. That CC Terms and Conditions makes me a bit sad. Pushing responsibility into the developer’s code is not a great way of dealing with their own API limitations. I’ve given them that feedback in the past.

    The existing example code is correct for 25 or less items. For an example of how to handle the bulk operations see the SynchronizeContacts methods in the ContactProvider. That code batches up a bunch of updates into one activity. You could easily modify that code to handle add operations (I might already have that in my production code).

    Send me any useful updates you might create. I’ll add them to the sample. Cheers!

Leave a Reply