Simon Miller Team : Web Development Tags : Web Development

MailChimp and Mail Groups

Simon Miller Team : Web Development Tags : Web Development

Long gone are the days where a developer would need to send bulk emails from his own website. Not only was this time consuming for the developer but it was fraught with possible points of failure – sending too many emails from the one address to the one host is an easy way to get your entire domain put on a spam blacklist.

Thankfully this pain has been removed entirely in recent years by offloading the work to marketing mail out companies such as MailChimp. With their developer API it becomes quite trivial to subscribe your customer base to a mailing list and then using MailChimp’s easy to use interface, construct your campaigns, email your subscribers and monitor your results.

For the best integration to your website, the developer API is the best way to go. There are many advanced methods available via the API such as bulk subscribing customers, convert HTML templates into plain text, and even trigger the campaign emails to send. I recently had to code against the API and chose to use the MCAPI.NET wrapper to make my life a little easier; this however was the source of my problem – the very limited documentation for the wrapper implementation itself.

The website I am working on allowed users to subscribe to sub-sets of the mailing list – MailChimp refers to these as Interest Groups – and based on the user’s choices they would receive differing mail campaigns. I knew how I wanted the final request string to look, were I to do it without the wrapper, but not sure of the syntax that the wrapper itself was expecting.

This is the raw request string:

us2.api.mailchimp.com/1.3/?method=listSubscribe&apikey=xxxxx&id=yyyyy&email_address=example@example.com&merge_vars[FNAME]=Firstname&merge_vars[LNAME]=Lastname&merge_vars[GROUPINGS][0][name]=Selections&merge_vars[GROUPINGS][0][groups]=Cats,Dogs,Fish

Broken down simply, this call would subscribe user example@example.com with the name Firstname Lastname, and assign the user to Interest Group “Selections”, checking the possible options of Cats, Dogs and Fish.

The MCAPI.NET wrapper was not as obvious as to how to achieve this. I have included the successful code below that I eventually worked out. Hopefully this will be of help to someone else.

 

The _groupId is the integer value of the top level group in MailChimp. This can be derived by calling ListInterestGroupings method of the API. The individual group options are simply passed through as strings – so make sure they match up to the values you have set up in MailChimp!