I am currently exploring the use of mailchimp-api-v3 in a Meteor project (1.4.1.3) and I particularly like the batch support it offers.
To make the call, I have enclosed it within Meteor's .wrapAsync
function (which had a bit of a learning curve, but I believe I have grasped it).
My suspicion is that there might be a conflict between how .wrapAsync
functions and how the author has structured the mailchimp-api-v3 package.
Below is the method I have utilized:
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 = {
//Taking just a few pieces of data for testing purposes
id: campaign.id,
type: campaign.type,
create_time: campaign.create_time
};
campaigns.push(doc);
});
return campaigns;
}
});
Furthermore, here are the errors shown on the console:
=> 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 came across this discussion on Stack Overflow which appears related, but I lack the expertise to troubleshoot or alter the package setup manually. Dependencies can be tricky!
I am eager to enhance my understanding, hence why I am seeking guidance through this question.
Thank you for taking the time to read this and potentially pointing me in the right direction.