首页 > 解决方案 > 使用 Node.js 客户端库将查询参数添加到 mailchimp 请求

问题描述

我正在尝试使用 @mailchimp/mailchimp_marketing npm 库从 MailChimp api 中列出我的所有兴趣,因为这是他们在文档中用作 node.js 示例的内容。

链接到 npm 库: https ://www.npmjs.com/package/@mailchimp/mailchimp_marketing

链接到此特定端点的相关文档:https ://mailchimp.com/developer/api/marketing/interests/list-interests-in-category/

现在,我可以通过那里的示例代码获得我的兴趣:


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

run();

问题是,默认情况下 MailChimp API 只返回列表中的前 10 个项目,而我需要 15 个。当然,有一种简单的方法可以更改这一点,方法是添加一个查询参数count=15。但是,我找不到使用listInterestCategoryInterests官方库提供的方法传递查询参数的任何方法。

!TL;博士!所以我的问题是:有人知道如何通过官方的 node.js npm 库将查询参数传递给 mailchimp API,还是我真的不得不完全放弃这个库,因为它不提供这个基本功能?

标签: node.jsmailchimpmailchimp-api-v3.0

解决方案


您需要将参数列为数组中的字符串:

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

注意:可能需要一个前缀,如下所示:

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

结果:

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

推荐阅读