Skip to content

Instantly share code, notes, and snippets.

@eibrahim
Created November 28, 2012 18:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eibrahim/4162985 to your computer and use it in GitHub Desktop.
Save eibrahim/4162985 to your computer and use it in GitHub Desktop.
Subscribe to Mailchimp fro Azure Mobile Service
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment