Created
November 28, 2012 18:13
-
-
Save eibrahim/4162985 to your computer and use it in GitHub Desktop.
Subscribe to Mailchimp fro Azure Mobile Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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