【问题标题】:Adding query param to mailchimp request with Node.js client library使用 Node.js 客户端库将查询参数添加到 mailchimp 请求
【发布时间】:2020-12-14 12:09:45
【问题描述】:

我正在尝试使用 @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.js mailchimp mailchimp-api-v3.0


    【解决方案1】:

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

    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] }
    

    【讨论】:

      【解决方案2】:
      const response = await mailchimp.lists.getListMembersInfo(listId,
                      {
                          count: 1000
                      });
      

      【讨论】:

        【解决方案3】:

        对于所有来到这里希望学习如何将 QUERY 参数传递到 mailchimp 营销库方法的人:

        查询参数取自 opts 对象 - 对象属性必须是驼峰式。

        opts 对象的方法参数而言 - 这取决于方法,您可能需要检查方法的源代码,但可能是第二个或第三个参数。

        至于具体方法的问题,应该是这样的:

        await client.lists.listInterestCategoryInterests(
            "list_id",
            "interest_category_id",
            { count: 15 }
          );
        

        【讨论】:

          猜你喜欢
          • 2021-06-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-11
          • 2022-12-26
          • 2017-09-05
          • 2018-08-29
          • 1970-01-01
          相关资源
          最近更新 更多