Skip to content

Instantly share code, notes, and snippets.

@captDaylight
Created September 26, 2018 15:03
Show Gist options
  • Save captDaylight/a7ea3d25fd87bed573b296f878186200 to your computer and use it in GitHub Desktop.
Save captDaylight/a7ea3d25fd87bed573b296f878186200 to your computer and use it in GitHub Desktop.
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