We prefer to maintain our mailing lists in Mailchimp and wanted an easy way to add new users to our email lists when they sign up to Taskorami . We added a server script during Insert to the Customer table in Azure Mobile Services.
It’s pretty straight forward – thanks to the nodejs library code at https://github.com/gomfunkel/node-mailchimp
Here is the code or get it form https://gist.github.com/4162985
var execute = function (method, availableParams, givenParams, callback) {
var request = require('request');
var finalParams = { apikey: 'XXXXXXXX' };
var currentParam;
for (var i = 0; i < availableParams.length; i++) {
currentParam = availableParams[i];
if (typeof givenParams[currentParam] !== 'undefined')
finalParams[currentParam] = givenParams[currentParam];
}
request({
uri: 'https://us6.api.mailchimp.com/1.3/?method=' + method,
method: 'POST',
headers: { 'User-Agent': 'azure' },
body: JSON.stringify(finalParams)
}, function (error, response, body) {
}
});
}
function addToMailChimp(item) {
try {
execute('listSubscribe', [
'id',
'email_address',
'merge_vars',
'email_type',
'double_optin',
'update_existing',
'replace_interests',
'send_welcome',
], { id: 'XXXXX', email_address: item.email }, function () {
});
} catch (ex) {
console.log(ex);
}
}
Resources
listsubscribe API method: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
Get updates about taskorami at http://eepurl.com/rEdH5