Skip to content

Instantly share code, notes, and snippets.

@1Marc
Last active August 29, 2015 14:16
Show Gist options
  • Save 1Marc/8e363230d27e1f73e9b1 to your computer and use it in GitHub Desktop.
Save 1Marc/8e363230d27e1f73e9b1 to your computer and use it in GitHub Desktop.
Sync MailChimp Subscription Status with Intercom
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