Post 请求销售合作伙伴 API 沙盒端点 return InvalidSignature
Post request to selling partner API sandbox endpoint return InvalidSignature
我目前正在尝试使用 ruby 和 HTTP.rb gem 创建文档并将其上传到 SP-API 沙箱环境。我的步骤是:
- 通过刷新令牌请求 LWA 访问令牌
- 代入角色并请求 STS 令牌
- 使用 AWS::SignV4 SDK
签署请求 header
- 使用body
json: { 'contentType' => 'text/tab-separated-values; charset=UTF-8' }
向端点/feeds/2020-09-04/documents
发送POST请求
然而,SP-API 一直返回 "code": "InvalidSignature"
给我。但我所有其他 'GET' 请求,如 get_orders、get_order_items 都正常工作。
以下是我发送请求的方式:
@url = '/feeds/2020-09-04/documents'
@body = if sandbox
{ 'contentType' => 'text/tab-separated-values; charset=UTF-8' }
else
{ 'contentType' => 'text/xml; charset=UTF-8' }
end
@request_type = 'POST'
response = http.headers(headers).send(@request_type.downcase.to_sym, request_url, json: @body)
我检查了 AWS::Signer::V4 文档,原来我也应该将正文传递给签名者。
signer.sign_request(http_method: @request_type, url: request_url, body: @body)
我发布了执行此操作的 amz_sp_api rubygem,但我欢迎贡献 ruby 代码以按照 SP-[=14 的要求加密提要提交=]: https://github.com/ericcj/amz_sp_api/issues/1
我目前正在尝试使用 ruby 和 HTTP.rb gem 创建文档并将其上传到 SP-API 沙箱环境。我的步骤是:
- 通过刷新令牌请求 LWA 访问令牌
- 代入角色并请求 STS 令牌
- 使用 AWS::SignV4 SDK 签署请求 header
- 使用body
json: { 'contentType' => 'text/tab-separated-values; charset=UTF-8' }
向端点
/feeds/2020-09-04/documents
发送POST请求
然而,SP-API 一直返回 "code": "InvalidSignature"
给我。但我所有其他 'GET' 请求,如 get_orders、get_order_items 都正常工作。
以下是我发送请求的方式:
@url = '/feeds/2020-09-04/documents'
@body = if sandbox
{ 'contentType' => 'text/tab-separated-values; charset=UTF-8' }
else
{ 'contentType' => 'text/xml; charset=UTF-8' }
end
@request_type = 'POST'
response = http.headers(headers).send(@request_type.downcase.to_sym, request_url, json: @body)
我检查了 AWS::Signer::V4 文档,原来我也应该将正文传递给签名者。
signer.sign_request(http_method: @request_type, url: request_url, body: @body)
我发布了执行此操作的 amz_sp_api rubygem,但我欢迎贡献 ruby 代码以按照 SP-[=14 的要求加密提要提交=]: https://github.com/ericcj/amz_sp_api/issues/1