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

Amazon SP-API调用getReportDocument获取订单报告报错咨询

SP-API getReportDocument接口调用报错排查

报错根因

两个报错本质都是RDT(受限数据令牌)申请时配置的资源路径错误导致:

  • 初始调用返回Unauthorized:申请RDT时仅配置了Orders v0系列接口的访问权限,完全没有覆盖Reports API的报告文档获取接口,令牌无对应接口访问权限。
  • 新增/reports/2021-06-30/reports路径后返回InvalidInput:该路径是创建、查询报告任务的接口路径,并非获取报告下载文档的接口路径,令牌权限和实际调用接口不匹配,触发无效文档ID的误报,并非传入的reportDocumentId本身格式错误。
  • 现有授权范围校验:已开通的Inventory and Order Tracking权限完全覆盖GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING类型报告的访问要求,不需要额外申请新的API授权角色。

修复方案

  1. 修正RDT申请时的受限资源路径
    调用2021-06-30版本Reports API的getReportDocument接口,需要新增的正确受限资源配置为:
    [
        'method' => 'GET',
        'path' => '/reports/2021-06-30/documents/{reportDocumentId}'
    ]
    
  2. 修正后的完整调用代码
    $cred = $credentials->getRdtCredentials([
        'restrictedResources' => [
            [
                'method' => 'GET',
                'path' => '/orders/v0/orders'
            ],
            [
                'method' => 'GET',
                'path' => '/orders/v0/orders/{orderId}/orderItems'
            ],
            [
                'method' => 'GET',
                'path' => '/orders/v0/orders/{orderId}/address'
            ],
            [
                'method' => 'GET',
                'path' => '/orders/v0/orders/{orderId}/buyerInfo'
            ],
            // 新增正确的报告文档接口权限配置
            [
                'method' => 'GET',
                'path' => '/reports/2021-06-30/documents/{reportDocumentId}'
            ]
        ]
    ]);
    
    $request = new Reports($cred, $config);
    $reportDocumentId = $params['reportDocumentId'];
    $reports = $request->getReportDocument($reportDocumentId);
    

注意事项

若修正路径后仍报权限错误,先确认实例化Reports客户端时使用的API版本为2021-06-30,旧版Reports API不支持RDT令牌鉴权,会持续返回权限错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 12:15:43