Search code examples
node.jsmailchimpmailchimp-api-v3.0

Adding query param to mailchimp request with Node.js client library


I am trying to list out all my interests from the MailChimp api using the @mailchimp/mailchimp_marketing npm library, as that is what they use as examples for node.js in their docs.

Link to the npm library: https://www.npmjs.com/package/@mailchimp/mailchimp_marketing

Link to the relevant documentation for this specific endpoint: https://mailchimp.com/developer/api/marketing/interests/list-interests-in-category/

Now, I can get my interests just fine with the example code there:


const run = async () => {
  const response = await client.lists.listInterestCategoryInterests(
    "list_id",
    "interest_category_id"
  );
  console.log(response);
};

run();

The problem is, that by default the MailChimp API only returns the first 10 items in the list, and I need 15. There is an easy way to change this, of course, by adding a query param count=15. However, I can't find any way to pass on a query param with the listInterestCategoryInterests method as provided through the official library.

!TL;DR! So my question is: Does anybody know how to pass on query params to the mailchimp API through the official node.js npm library, or do I really have to resort to just dropping the library entirely as it does not provide this basic functionality?


Solution

  • You need to list params as a string in an array:

    const response = await client.lists.listInterestCategoryInterests({fields:[    "list_id,interest_category_id"]}
      );
    

    NOTE: A prefix maybe required as per below:

    const response = await mailchimp.reports.getAllCampaignReports({fields:["reports.campaign_title,reports.clicks"]})
    

    Result:

    [0] {
    [0]   reports: [
    [0]     { campaign_title: 'COACT EMAIL CAMPAIGN', clicks: [Object] },
    [0]     { campaign_title: '', clicks: [Object] }
    [0]   ]
    [0] }