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

调用Amazon SP-API getItemOffersBatch遇InvalidInput错误求助

Amazon SP-API getItemOffersBatch接口返回InvalidInput错误排查

问题现象

调用Amazon SP-API的getItemOffers单个ASIN接口可正常返回结果,但调用getItemOffersBatch批量接口时,返回400响应,错误信息无有效细节:

{
  "code": "InvalidInput",
  "message": "InvalidInput",
  "details": ""
}

正常运行的单个接口代码

libSeller.getItemOffers = async function (asin) {
  try {
    let apiPath='/products/pricing/v0/items/' + asin + '/offers';
    let sellingPartner = new SellingPartnerAPI(mwsConfig);
    let res = await sellingPartner.callAPI({
        api_path:apiPath,
        method:'GET',
        query:{MarketplaceId:account.MarketplaceId, ItemCondition:'New'}
    }).catch(err => {
        console.error(err);
    });
    return res;
  }
  catch (err) {
    console.error(err);
    return null;
  }
}

报错的批量接口代码

libSeller.getItemOffersBatch = async function (asins) {
  try   {
    let sellingPartner = new SellingPartnerAPI(mwsConfig);
    let requests=[];
    asins.forEach(asin => { 
        requests.push({'uri':'/products/pricing/v0/items/' + asin + '/offers', method:'GET', MarketplaceId:account.MarketplaceId, ItemCondition:'New'});
    });
    console.log(requests);
    let res = await sellingPartner.callAPI({
        api_path:'/batches/products/pricing/v0/itemOffers',
        method:'POST',
        body:{'getItemOffersBatchRequestBody':{'requests':requests}}
    }).catch(err => {
        console.error(err);
    });
    return res;
  } catch (err) {
    console.error(err);
    return null;
  }
}

栈追踪信息

CustomError: InvalidInput
    at SellingPartner.callAPI (/mnt/c/Users/John/dev/repricer3/node_modules/amazon-sp-api/lib/SellingPartner.js:658:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async libSeller.getItemOffersBatch (/mnt/c/Users/John/dev/repricer3/libs/libSeller.js:172:13) {
  code: 'InvalidInput',
  details: '',
  type: 'error'
}

问题原因

批量接口的请求体格式不符合SP-API规范:

  • 单个接口的参数放在query中,但批量接口里每个请求的参数需要封装在parameters对象内,不能直接与uri、method同级。
  • 原代码把MarketplaceId和ItemCondition直接平铺在request对象中,违反了批量接口的参数结构要求。

修正后的批量接口代码

libSeller.getItemOffersBatch = async function (asins) {
  try   {
    let sellingPartner = new SellingPartnerAPI(mwsConfig);
    let requests=[];
    asins.forEach(asin => { 
        requests.push({
            'uri': '/products/pricing/v0/items/' + asin + '/offers',
            'method': 'GET',
            // 核心修正:将参数放入parameters字段
            'parameters': {
                'MarketplaceId': account.MarketplaceId,
                'ItemCondition': 'New'
            }
        });
    });
    console.log(requests);
    let res = await sellingPartner.callAPI({
        api_path: '/batches/products/pricing/v0/itemOffers',
        method: 'POST',
        body: {
            'getItemOffersBatchRequestBody': {
                'requests': requests
            }
        }
    }).catch(err => {
        console.error(err);
    });
    return res;
  } catch (err) {
    console.error(err);
    return null;
  }
}

关键注意事项

  • 批量接口的每个request必须遵循SP-API批量请求结构,参数需嵌套在parameters中,不能直接平铺。
  • 确保asins数组长度不超过20个(SP-API对该批量接口的限制)。
  • 检查account.MarketplaceId的有效性,确保与单个接口使用的一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 06:15:13