You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于stripe.reporting.reportRuns.create返回文件转JSON的技术问询

问题:Stripe报告能否直接获取JSON格式数据?

调用stripe.reporting.reportRuns.create接口后返回的是文件相关数据,目前的实现流程是先通过Stripe的Get File API获取xlsx文件,再用外部npm模块转换为JSON数据。代码示例如下:

let data = req.query; const reportRun = await stripe.reporting.reportRuns.create({ report_type: "balance.summary.1", parameters: { interval_start: data.startDate, interval_end: data.endDate, timezone: "America/Los_Angeles", columns: ["category", "description", "net_amount", "currency"], }, });

const url = reportRun.result.url;
const id = reportRun.result.id;
const fileLink = await stripe.fileLinks.create({ file: id, }); //Reset of the code is xlsx to JSON data

期望得到的JSON数据格式:

[
{
"category": "starting_balance",
"description": "Starting balance (2023-02-28)",
"net_amount": 33871.49,
"currency": "usd"
}
]

请问是否有更直接的方式获取JSON格式的数据,无需转换xlsx文件?


解决方案

有更直接的方式,无需转换xlsx文件。在调用stripe.reporting.reportRuns.create时,只需在parameters中添加file_format: "json"参数,即可让Stripe直接生成JSON格式的报告文件,后续直接获取文件内容即可。

修改后的代码示例:

let data = req.query; 
const reportRun = await stripe.reporting.reportRuns.create({ 
  report_type: "balance.summary.1", 
  parameters: { 
    interval_start: data.startDate, 
    interval_end: data.endDate, 
    timezone: "America/Los_Angeles", 
    columns: ["category", "description", "net_amount", "currency"],
    file_format: "json" // 指定生成JSON格式报告
  }, 
});

const fileId = reportRun.result.id;
const fileLink = await stripe.fileLinks.create({ file: fileId });
// 直接请求fileLink.url即可获取你期望的JSON结构数据,无需额外转换

这样生成的报告文件内容会完全匹配你期望的JSON格式,省去了xlsx转JSON的步骤。


内容的提问来源于stack exchange,提问作者Rahul T.O

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:07:20