February 23

CampaignMonitor API is Annoying

Ok, let’s be honest, I never really was any good at following directions. That’s probably why I’m an entrepreneur today. That’s also why I spent a few hours trying to find out why I kept getting this error when trying to talk to the CampaignMonitor API in the most basic way:

(101) Invalid ListID

Ok, yeah I didn’t read every line of the documentation. I’ve worked with countless API’s in the past and continue to do so. They’re all very simple on the surface but they all have their little nuances. It turns out that the CM API has one of the most annoying quirks that I’ve ever seen.

I’ll start at the beginning. I decided I wanted to use the API to add subscribers to a list on CM. That’s pretty straightforward, I thought. You know, some sort of authentication mechanism, then provide the email address in some REST-ful way. I glanced at the docs to see that there is a SOAP interface. I quickly decide on that since usually this bloated way of interacting with a simple API is the quickest to code. So, I fire up a SoapClient and throw the four parameters at it and I get that 101 error. Again and again, I try every different way I can think of. Same 101 error.

During the pulling-out-hair stage, I ran across this post: Using Zend_Soap_Client with the Campaign Monitor API which pointed toward the need for a special input header. That prompted me to write a wrapper. I’ll get to that in a sec. It turns out that the input header wasn’t required after all.

When I glanced at the CM API documentation, I saw that there are 3 parameters required for the Subscriber.Add call: ApiKey, ListID, Email. Easy enough. It took a sec to find the ApiKey. The Email parameter is easy. So is the ListID, or so I thought. To find that, I just clicked on the list name in the CM gui and then there, in the address bar, was exactly what I was looking for:


Nope. Its a ListID but not the ListID. No, I had to click on the “edit list name/type” link to find that. What a waste of half a day.

Alright, I’m done blaming CampaignMonitor for my inability to RTFM. I wrote a very quick wrapper around the Zend_Soap_Client class specifically for CampaignMonitor API oddities. Hopefully this will save someone else some headache. Download it here:

CampaignMonitor.php

Use it like so:

<?php
$cm = new CG_CampaignMonitor(
    'yourApiKey', 
    'yourListID'
);
$result = $cm->AddSubscriber(
    array(
        'Email'=>'test@example.com', 
        'Name'=>'Test Subscriber'
    )
);
?>