Integrating Campaign Monitor API With WordPress

1 Comment | This entry was posted on May 04 2011

One of the most enjoyable things in software development is combining different tools or datasets together into one application. Sometimes this is done to build interesting mashups or more usually to automate an otherwise manual task. Is the case of using the Campaign Monitor API is to prevent having to do a repetitive task manually.

The project I have been working on for the last two weeks is a WordPress blog that allows site visitors to subscribe to a section (or category) of the site to be notified when a new post has been added. As with this project it is expected to have many hundreds or thousands of subscribers, it is not feasible to send mail directly from the web server because of the overhead and the potential of having the server black listed by spam prevention services. Therefore Campaign Monitor was chosen to send any new post notifications out to the subscribers via the API.

The Campaign Monitor API is very easy to use and does nearly everything that is possible through the normal web based interface.  For this solution there were three API calls required to achieve the necessary task, 1. add new subscribers to a list; 2. create a new campaign for each new post; and 3. send the campaign to the subscribers in the list.

A WordPress plugin was created to display a form to populate required Campaign Monitor values such as client and list Ids and to define the functions that will execute the tasks. The tasks are broken down as follows:

  1. A new client list was first added manually to the Campaign Manager client. In the site, new subscribers were already being saved to the WordPress wp_users table. A new function was created and called from this block of code to add subscribers to the specified list.
  2. Each time a new post is created, a hook is used to call a function that gathers that post information and creates a new campaign which is assigned to the existing list. However, before this is done a new html campaign (edm) is created from a template but populated with the post’s title and URL so that the link can be clicked in the receivers email client. This URL is supplied in the API call when creating the new campaign.
  3. After the campaign has been created, another function is been called to send it of to all those in the subscriber list.

And it’s done. The API is simple to use and requires little effort to get started. It can be downloaded from Github in 5 popular web development languages and is supplied with sample code. Each call to update or read from the API is achieved with just a handful of lines and can be sent and received in either XML or JSON. The documentation is clear and intuitive.

For more information, visit the website.