Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A node worker for firebase to add a user to mailchimp
var mcapi = require('./node_modules/mailchimp-api/mailchimp');
var usersRef = db.ref('users');
var mc = new mcapi.Mailchimp('xxxxxxxxxx-api-key-us4');
var user = snapshot.val();
var key = snapshot.key;
if(user &&{
var listId = 'xxxx-list-id-xxxx';
var name = user.displayName || '';
var fname = name.split(' ')[0];
var lname = name.split(' ').slice(1).join(' ');
mc.lists.subscribe({id: listId,
merge_vars: {
name: name,
LNAME: lname,
FNAME: fname
double_optin: false,
update_existing: true,
send_welcome: false
}, function(data) {
db.ref('users/'+ key +'/added_to_mailchimp').set(true);
function(error) {
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.