Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. var Intercom = require('intercom.io');
  2.  
  3. var options = {
  4. apiKey: "intercomapikey",
  5. appId: "intercomappid"
  6. };
  7.  
  8. var intercom = new Intercom(options);
  9.  
  10. var MailChimpAPI = require('./node_modules/mailchimp-api/mailchimp');
  11. var apiKey = 'mailchimpkey';
  12. var mc = new MailChimpAPI.Mailchimp(apiKey);
  13. var list_id = 'mailchimplistid';
  14.  
  15. // you have to manually increment start page 0++ until memberData results are null
  16. // also you should import status: "cleaned" and start at page 0
  17. mc.lists.members({id: list_id, status: "unsubscribed", opts: {limit: 100, start:0}}, function(memberData) {
  18. memberData.data.forEach(function(member) {
  19. if (member.status != "subscribed") {
  20. intercom.updateUser({
  21. email: member.email,
  22. unsubscribed_from_emails: true
  23. }, function (err, res) {
  24. if (err) {
  25. console.log(err);
  26. } else {
  27. console.log(res.email, 'unsubscribed');
  28. }
  29. });
  30. }
  31. })
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement