node.js - 使用 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,还是我真的不得不完全放弃这个库,因为它不提供这个基本功能?
解决方案
您需要将参数列为数组中的字符串:
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] }
推荐阅读
- python - NeuroMorpho.org - 从多个 API 页面获取结果
- windows - 什么是 MongoDB 二进制文件,它们位于何处?
- powerbi - 基于切片器(其他表)在矩阵视觉 Power BI 中显示/隐藏列
- javascript - 循环 json 对象以获取特定键的值
- jquery - 它的问题是在 url 中使用“-”后删除所有查询字符串
- java - 为 XSS 转义括号
- node.js - vsc中代码节点自动完成的问题
- sql - 按值列表排序
- firebase - firebase 管理员:您的应用程序已使用不受支持的 Google Cloud SDK 或 Google Cloud Shell 的最终用户凭据进行身份验证
- pascalscript - 掩码编辑:未知标识符“TEXT”