【问题标题】:retrieve all customers email address stripe node.js检索所有客户的电子邮件地址条带 node.js
【发布时间】:2021-12-23 10:56:14
【问题描述】:

我有这个功能可以尝试检索所有客户的条带电子邮件:

 const customers = await stripe.customers.list({
  });

    var customerEmail = customers.data[0].email;
    console.log(customerEmail)

我正在尝试从条带返回用户的所有电子邮件地址。问题是,当我记录它时,它只返回第一个,因为我有data[0]。我需要所有这些,但我不能把它放在一个循环中,因为我在循环什么。有没有办法正确地做到这一点?

【问题讨论】:

  • customers.data 包含什么?

标签: javascript node.js stripe-payments


【解决方案1】:

您要索引的data 属性是一个可以迭代的数组[1]。

const customers = await stripe.customers.list({});

customers.data.forEach(customer => {
  console.log(customer.email);
});

[1]https://stripe.com/docs/api/customers/list

【讨论】:

  • 感谢您的回复。但是,当我刚刚运行它时,它给了我一个类型错误:UnhandledPromiseRejectionWarning: TypeError: customers.forEach is not a function。 ?
  • 抱歉,应该是customers.data.forEach。编辑了我的答案。
  • 不用担心。感谢您的帮助,谢谢:)
猜你喜欢
  • 2021-12-12
  • 2021-12-23
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 2011-11-07
  • 1970-01-01
  • 2021-12-12
  • 2012-10-03
相关资源
最近更新 更多