Mike Wickett
Mike Wickett

Reputation: 13

Trouble with Meteor.wrapAsync and mailchimp-api-v3

I'm trying to use mailchimp-api-v3 in a Meteor (1.4.1.3) project (I like the batch support in this one)

I've wrapped the call in Meteor's .wrapAsync (bit of a learning curve there, but I think I've got it).

I'm thinking there's a conflict between the way .wrapAsync works and the way the author has written the mailchimp-api-v3 package.

Here is my method:

var Mailchimp = require('mailchimp-api-v3')

Meteor.methods({

getCampaigns: function() {
    console.log("running...");

    var mailchimp = new Mailchimp(Meteor.settings.private.mailChimp.apiKey); 

    var getCampaignsAsyncToSync = Meteor.wrapAsync(mailchimp.request, mailchimp);
    var resultOfGetCampaigns = getCampaignsAsyncToSync({method: 'get', path: '/campaigns'}, {});

    var campaigns = [];

    _.each(resultOfGetCampaigns.campaigns, function(campaign){
        var doc = {
            //Just grab a few pieces of data for testing
            id: campaign.id,  
            type: campaign.type,
            create_time: campaign.create_time
        };

        campaigns.push(doc);
    });

    return campaigns;
}
});

And the console error the results:

=> Meteor server restarted
I20161205-14:32:22.908(-5)? running...
W20161205-14:32:24.134(-5)? (STDERR) Unhandled rejection TypeError: done is not a function
W20161205-14:32:24.135(-5)? (STDERR)     at /Users/michaelwickett/Sites/sagecomm-projects/academica-reporter/node_modules/mailchimp-api-v3/index.js:507:9
W20161205-14:32:24.135(-5)? (STDERR)     at processImmediate [as _immediateCallback] (timers.js:383:17)
W20161205-14:32:24.135(-5)? (STDERR) From previous event:
W20161205-14:32:24.135(-5)? (STDERR)     at Mailchimp.request (/Users/michaelwickett/Sites/sagecomm-projects/academica-reporter/node_modules/mailchimp-api-v3/index.js:506:13)
W20161205-14:32:24.136(-5)? (STDERR)     at packages/meteor/helpers.js:118:1
W20161205-14:32:24.136(-5)? (STDERR)     at [object Object].getCampaigns (server/methods.js:11:36)
W20161205-14:32:24.136(-5)? (STDERR)     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1711:12)
W20161205-14:32:24.136(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:711:19
W20161205-14:32:24.136(-5)? (STDERR)     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
W20161205-14:32:24.136(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:709:40
W20161205-14:32:24.137(-5)? (STDERR)     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
W20161205-14:32:24.137(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:707:46
W20161205-14:32:24.137(-5)? (STDERR)     at Session.method (packages/ddp-server/livedata_server.js:681:23)
W20161205-14:32:24.137(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:551:43

I found this thread Meteor - Wrapping NPMs with Meteor.wrapAsync which seems related, but I don't understand enough to troubleshoot, or manually override the way the package is setup. Dependencies!

I'd like to understand though, hence my question.

Appreciate your time in reading and giving me a push in the right direction.

Upvotes: 1

Views: 113

Answers (1)

kkkkkkk
kkkkkkk

Reputation: 7738

You do not need to use .wrapAsync, the package you are using supports Promise and Meteor methods play nicely with that. See this: How to return from remote API call in Meteor Method?

Upvotes: 1

Related Questions