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

CURL转Google Apps Script后startRow/endRow参数失效求助

解决Google Apps Script中startRow与endRow参数失效问题

你的startRow和endRow参数失效,核心原因有三点:

  • 请求体(payload)缺失原CURL中携带的filterModel和sortModel关键参数,接口需完整请求上下文才能解析分页参数
  • 未显式指定请求方法为POST,UrlFetchApp默认使用GET请求,无法正确提交POST格式的请求体
  • URL未完整拼接原CURL中的d1、d2、path查询参数

修复后的完整代码

const token = "5edfe8277ff2a5.941835169784f269a9244f13350db36eedb814d1";
// 对俄文路径进行URL编码,避免乱码
const targetPath = encodeURIComponent("Женщинам/Одежда");
const requestUrl = `http://mpstats.io/api/wb/get/category?d1=2020-07-13&d2=2020-08-11&path=${targetPath}`;

const requestOptions = {
  // 显式指定POST请求方法
  method: "POST",
  headers: {
    'X-Mpstats-TOKEN': token,
    'Content-Type': 'application/json'
  },
  // 完整还原原CURL的请求体参数
  payload: JSON.stringify({
    "startRow": 0,
    "endRow": 10,
    "filterModel": {"id":{"filterType":"number","type":"equals","filter":13495594,"filterTo":null}},
    "sortModel": [{"colId":"revenue","sort":"desc"}]
  })
};

// 执行请求并解析响应
const response = UrlFetchApp.fetch(requestUrl, requestOptions);
const responseData = JSON.parse(response.getContentText());
console.log(responseData);

关键修复点说明

  • 补全请求体参数:原CURL的data-raw包含filterModel和sortModel,接口依赖这些参数确定数据筛选、排序规则,分页参数需配合这些规则才能生效
  • 指定POST方法:UrlFetchApp默认使用GET,必须显式声明method: "POST"才能正确提交JSON格式的请求体
  • URL编码路径:原路径中的俄文需用encodeURIComponent编码,避免URL解析错误导致请求失败

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 01:20:41