使用Node.js客户端库将查询参数添加到mailchimp请求中 [英] Adding query param to mailchimp request with Node.js client library
问题描述
我正在尝试使用@ mailchimp/mailchimp_marketing npm库从MailChimp api中列出我的全部兴趣,因为这就是他们在文档中作为node.js示例使用的内容.
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.
链接到npm库: https://www.npmjs.com/package/@mailchimp/mailchimp_marketing
链接到该特定端点的相关文档:https://mailchimp.com/developer/api/marketing/interests/list-interests-in-category/
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();
问题是,默认情况下,MailChimp API仅返回列表中的前10个项目,而我需要15个项目.当然,通过添加查询参数 count =15
.但是,我找不到任何通过官方库提供的 listInterestCategoryInterests
方法传递查询参数的方法.
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!所以我的问题是:是否有人知道如何通过官方的node.js npm库将查询参数传递给mailchimp API,还是我真的不得不诉诸于完全删除该库,因为它不提供此基本功能?
!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?
推荐答案
您需要以数组中的字符串形式列出参数:
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"]})
结果:
[0] {
[0] reports: [
[0] { campaign_title: 'COACT EMAIL CAMPAIGN', clicks: [Object] },
[0] { campaign_title: '', clicks: [Object] }
[0] ]
[0] }
这篇关于使用Node.js客户端库将查询参数添加到mailchimp请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!