Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.