Move to mailchimp NPM package

I’d like to move to npm. When I try to use the npm mailchim packge https://www.npmjs.com/package/mailchimp-api-3 I got the following error:

I20170908-10:57:38.566(2)? Exception while invoking method 'registerNewsletter' SyntaxError: Unexpected token {
I20170908-10:57:38.568(2)?     at exports.runInThisContext (vm.js:53:16)
I20170908-10:57:38.570(2)?     at Module._compile (module.js:373:25)
I20170908-10:57:38.571(2)?     at Object.Module._extensions..js (module.js:416:10)
I20170908-10:57:38.572(2)?     at Module.load (module.js:343:32)
I20170908-10:57:38.574(2)?     at Function.Module._load (module.js:300:12)
I20170908-10:57:38.576(2)?     at Module.require (module.js:353:17)
I20170908-10:57:38.578(2)?     at require (internal/module.js:12:17)
I20170908-10:57:38.587(2)?     at Object.<anonymous> (C:\Projects\...\code\node_modules\mailchimp-api-3\ind
ex.js:1:18)
I20170908-10:57:38.588(2)?     at Module._compile (module.js:409:26)
I20170908-10:57:38.589(2)?     at Object.Module._extensions..js (module.js:416:10)

The code I used was:


        let Mailchimp = require('mailchimp-api-3');
        let mailchimp = new Mailchimp("...");

        mailchimp.members.create("...", {
            email_address: email,
            merge_fields: {},
            status: 'subscribed',
        }).then(user => {
            console.log(user);
        }).catch(e => {
            console.log(e);
        });

The atmosphere package works fine.

Hi.

In case this is useful for you or someone else. I was able to setup the mailchimp 3.0 API to add new people to a list by using the NPM node-mailchimp package and reviewing Meteor’s HTTP API docs. My working server side code is below:

Meteor.methods({
 'mailChimpAPICall': function () {
        console.log('call initiatied on server');
        var mailchimp = Meteor.settings.private.mailChimpAPI;
        var api = 'apikey ' + mailchimp;
        try {
            HTTP.call('POST', 'https://<dataCenter>.api.mailchimp.com/3.0/lists/<listID>/members', {
                headers: {
                    'Authorization': api
                },
                data: {
                    email_address: <emailAddress>,
                    status: 'subscribed'
                },

            });

            console.log('it worked!');
            return true;

        } catch (error) {
            console.log(error);
            return false;
        }
    }
});

Good luck!

2 Likes