Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
router.put('/user/:refCode', function(req, res, next) {
if (!req.params.refCode) res.json({ result: 'error', msg: 'must send an referral code'});
var newEmail = req.body.email ? req.body.email : '';
mailchimp.get({
path: 'lists/' + listID + '/members?unique_email_id=' + req.params.refCode,
})
.then(function(search) {
const user = search.members[0];
let newReferrals = user.merge_fields.REFERRALS;
if (user.merge_fields.REFERRALS.indexOf(newEmail) < 0) {
newReferrals = newReferrals === '' ? newEmail : user.merge_fields.REFERRALS + ',' + newEmail;
}
mailchimp.patch({
path: 'lists/' + listID + '/members/' + md5(user.email_address.toLowerCase()),
body: {
merge_fields: {
REFERRALS: newReferrals,
}
}
})
// ....
}
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.