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

如何通过Postman提取VTEX API响应的卖家佣金字段并批量输出

Postman提取VTEX卖家佣金字段实现方案

你原有的Tests脚本仅做了响应体存在的校验,替换为以下代码即可实现批量提取、结构化输出需求:

// 解析接口返回的JSON响应
const respData = pm.response.json();
// 读取当前迭代CSV中对应的卖家ID
const sellerId = pm.iterationData.get("sellerId");
// 提取默认类目下的两个佣金字段(响应为数组结构,取第一个元素即default类目配置)
const productCommissionPercentage = respData[0].productCommissionPercentage;
const freightCommissionPercentage = respData[0].freightCommissionPercentage;

// 基础响应校验
pm.test("接口请求成功", function () {
    pm.response.to.have.status(200);
    pm.expect(productCommissionPercentage).to.be.a("number");
    pm.expect(freightCommissionPercentage).to.be.a("number");
});

// 字段存入变量供Runner导出
pm.variables.set("productCommissionPercentage", productCommissionPercentage);
pm.variables.set("freightCommissionPercentage", freightCommissionPercentage);

// 汇总全量结果
let allResult = pm.collectionVariables.get("sellerCommissionResult") 
    ? JSON.parse(pm.collectionVariables.get("sellerCommissionResult")) 
    : [];
allResult.push({
    sellerId: sellerId,
    productCommissionPercentage: productCommissionPercentage,
    freightCommissionPercentage: freightCommissionPercentage
});
pm.collectionVariables.set("sellerCommissionResult", JSON.stringify(allResult));

// 最后一个卖家请求完成后,控制台打印结构化表格
if (pm.info.iteration === pm.info.iterationCount - 1) {
    console.table(allResult);
}

操作步骤

  • 清空原有Tests栏的代码,把上述代码完整粘贴保存
  • 打开Postman Runner导入你的卖家CSV文件,确认Runner能识别首列sellerId字段
  • 启动批量运行,全部请求执行完成后,打开Postman控制台就能看到和你预期格式一致的三列表格,直接复制即可使用
  • 如果需要导出文件,在Runner结果页选择导出结果,导出的文件中包含所有提取到的字段,可直接转成CSV/Excel留存

注意点

如果接口返回的数组中包含多个类目的佣金配置,修改respData[0]的索引值即可匹配你需要提取的类目,当前代码默认和你给出的响应示例对齐,取categoryId为default的第一条配置。

内容的提问来源于stack exchange,提问作者Rhendel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.03 09:57:27