Last active
August 29, 2015 14:16
-
-
Save 1Marc/8e363230d27e1f73e9b1 to your computer and use it in GitHub Desktop.
Sync MailChimp Subscription Status with Intercom
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 Intercom = require('intercom.io'); | |
var options = { | |
apiKey: "intercomapikey", | |
appId: "intercomappid" | |
}; | |
var intercom = new Intercom(options); | |
var MailChimpAPI = require('./node_modules/mailchimp-api/mailchimp'); | |
var apiKey = 'mailchimpkey'; | |
var mc = new MailChimpAPI.Mailchimp(apiKey); | |
var list_id = 'mailchimplistid'; | |
// you have to manually increment start page 0++ until memberData results are null | |
// also you should import status: "cleaned" and start at page 0 | |
mc.lists.members({id: list_id, status: "unsubscribed", opts: {limit: 100, start:0}}, function(memberData) { | |
memberData.data.forEach(function(member) { | |
if (member.status != "subscribed") { | |
intercom.updateUser({ | |
email: member.email, | |
unsubscribed_from_emails: true | |
}, function (err, res) { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log(res.email, 'unsubscribed'); | |
} | |
}); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment