Struggling with integrating Meteor.wrapAsync with the mailchimp-api-v3

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.

Answer №1

There is no need for using .wrapAsync, as the current package you are utilizing fully supports Promises and Meteor methods work seamlessly with them. For further details, refer to: How to handle returning from remote API call within a Meteor Method?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modifying the chart width in Chart.js: A step-by-step guide

After creating a chart using Chart Js, I encountered an issue where the chart did not fit within the specified width. Adjusting the attributes of canvas proved to be ineffective, specifically with regards to the width attribute. Despite changing the value, ...

Troubleshooting a Vue.js formatting problem in Visual Studio 2019

Encountering an issue with VS2019 while attempting to format this code section. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="milestone.ascx.cs" Inherits="uc.dms.milestone" %> <section class="content-header"> <h1> ...

What purpose does Webpack serve in injecting React?

Within my webpack entry file, I have the following code snippet: import ReactDOM from 'react-dom'; import Layout from './components/Layout'; // ... dialog = document.createElement("dialog"); ReactDOM.render(<Layout dialog={dialog} ...

Error: The name property is not defined and cannot be read in the Constructor.render function

Having trouble building a contact form and encountering an error when trying to access the values. I've checked for bugs in the console multiple times, but it seems like something is missing. Can anyone provide assistance? var fieldValues = { ...

Does the "onevent" option get disregarded for jsf.ajax.request in JSF

In my attempt to develop an interactive chat web application using Java EE 7, I am specifically utilizing JSF 2.2 with ajax. The concept involves having a slow pending asynchronous ajax request waiting on the server for each unique client. When a new mess ...

Issue with alert not being triggered in browser when using HTML and JavaScript function

Just starting out with HTML and Javascript! I'm working on a simple program where users can input a card number, and the browser should indicate whether it is valid (between 13-16 digits) or not. The website looks great, but I'm not getting an ...

What steps should be taken in configuring the package.json to prioritize installing the local package before attempting to install from the registry or repository?

Is it possible to configure the npm install process within the package.json file so that it first attempts to install a new package from a local source, and if not available, then installs it from an external location? I am aware of the versioning syntax ...

Using the `await` command may lead to the variable losing its scope

Utilizing the await keyword to retrieve data from the database has been causing me some trouble. The variable secuity_ok is set to true on one line, but inexplicably changes to false on the following line. What could be causing this issue? It's worth ...

The local copy of Jquery.min.js is failing to trigger the window load function

Recently, I encountered an issue with the focus of tabs while working with jQuery. Initially, everything was fine when I included: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> in my JSP file. The wi ...

Generating unique names based on input from users

We are working with an array containing names and an input field where users can enter a string to receive name suggestions. The array includes names like Alex and Anna, and when the user types "a," we want to suggest these names. Below is the code snippet ...

difficulty encountered when passing session variable on PHP pages

In my project, I have two important PHP pages: quizaction.php and result.php. The functionality involves passing variables from quizaction.php to result.php. Below is an overview of my code: <?php include 'db.php'; session_start( ...

Discover the outcome of two asynchronous ajax requests using XHR's onprogress event-handler

My current challenge involves seeking out images within an ajax request response and extracting the src URL for utilization in another ajax request. I am aiming to monitor the loading progress of each image and display the resulting progress in a designat ...

using javascript to target a specific css selector attribute

I have a CSS file with the following code: .datagrid table tbody td { color: #00496B; border-left: 1px solid #E1EEF4; font-size: 16px ;font-weight: normal; } Is there a way to use JavaScript to dynamically change the font size? The code below worked ...

What is the function of async in Next.js when triggered by an onClick

Need help with calling an async function pushData() from a button onClick event async function pushData() { alert("wee"); console.log("pushing data"); try { await query(` //SQL CODE `); console.log("Done&quo ...

Using ng-repeat and selectize in AngularJS to populate a multi-select drop-down with values and set selected values

In this instance, I was able to achieve pure HTML select multiple functionality by using this example (JS Bin of pure html select tag). However, instead of sticking to just the pure HTML approach, I opted to use the Selectize plugin. The confusion arose w ...

React State Update Triggered by Changing Hidden Input/Textarea Value - No User Input Required

To activate a function when the contents of a hidden input, textarea, or textfield change in React without requiring user input to trigger it, you will need to dynamically adjust the value of the hidden input and then have the function automatically exec ...

Capture a screenshot of an embedded object and include it in an email using the mailto function

Is there a way to capture a screenshot of a flash object on a webpage and then send it via email using a mailto: form submission to a designated address? I have attempted to use different JavaScript techniques, but none seem to be successful. Appreciate a ...

Tips for utilizing the for each function within a for loop

Looking to showcase prices alongside each product based on their unique sku value, I've put together a price list. An array of data is being iterated through and pushed into the div container. var arr = [ { "sku": "552", "title": "orange", "pric ...

Guide on waiting for AWS assumeRole before proceeding with defining the module

I'm currently working on a module that needs to export functions and variables, but before it can do that, it must switch user roles. Here is the code snippet I've come up with. What I need is for the anonymous async function to execute first, an ...

Preventing Angular $rootElement.on('click') from affecting ReactJS anchor tag interactions

Running both AngularJS and ReactJS on the same page has caused an issue for me. Whenever I click on a ReactJS <a> tag, Angular's $rootElement.on('click) event is triggered and the page redirects. I need to perform some functionality in Re ...