亚马逊销售合作伙伴API请求

时间:2020-10-14 20:48:46

标签: c# .net amazon-web-services

我正在尝试使用Amazon的新销售伙伴API来访问直接履行/供应商中央帐户。我已尽我所能按照文档进行操作,但无法通过简单的po请求调用来工作。这是我请求中的所有要素。我不知所措,如果任何部分实际上是错误的。我不知道有什么方法可以像使用亚马逊MWS便笺本那样测试所有元素的有效性。

规范要求

GET
/vendor/directFulfillment/orders/v1/purchaseOrders
createdAfter=2020-10-05T23%3A00%3A00-08%3A00&createdBefore=2020-10-09T23%3A00%3A00-08%3A00
host:sellingpartnerapi-na.amazon.com
user-agent:My, Selling, Tool/1.0, (Language=C#.NET; Platform=Windows/10)
x-amz-access-token:Atza|IwEBIG0G7EXAMPLE
x-amz-date:20201014T193028Z

host;user-agent;x-amz-access-token;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

要签名的字符串

AWS4-HMAC-SHA256
20201014T193352Z
20201014/us-east-1/execute-api/aws4_request
d8efa99344ee27ae5505888ac5069f78734af9a95637485396274f8e773e2784

凭据范围

20201014/us-east-1/execute-api/aws4_request

授权标头

AWS4-HMAC-SHA256 Credential=AKIAUEXAMPLE/20201014/us-east-1/execute-api/aws4_request, SignedHeaders=host;user-agent;x-amz-access-token;x-amz-date, Signature=cab976c4d1d2546328e19ff2314f888d0c4b25da4d36f66e53a6614c37b92dff

这是我们得到的错误响应。

{Connection: keep-alivex-amzn-RequestId: 728bd01f-32ec-49d3-b845-558f4970014ax-amzn-ErrorType: InvalidSignatureExceptionx-amz-apigw-id: Uaxq-G6MoAMF6Cg=Date: Wed, 14 Oct 2020 20:44:02 GMT}

1 个答案:

答案 0 :(得分:1)

显示您签名的错误响应不正确。此外,您可以测试更简单的 API 来测试与您的 AWS 的连接。

试试这个,product-pricing-api,https://github.com/amzn/selling-partner-api-docs/blob/main/references/product-pricing-api/productPricingV0.md

  • 首先,使用refresh_token和grant_type(refresh_token)发送post到https://api.amazon.com/auth/o2/token并获取access_token;

  • 二、创建请求,并添加Header。

    Request request = new Request.Builder()
                    .url("https://sellingpartnerapi-na.amazon.com/products/pricing/v0/price?MarketplaceId=A2EUQ1WTGCTBG2&Skus="+sku+"&ItemType=Sku")
                    .method("GET", null)
                    .addHeader("x-amz-access-token","your token")
                    .build();
    


  • 第三,使用此实用程序 AWSSigV4Signer.java 签署您的请求。参考“步骤 1. 配置您的 AWS 凭证”和“步骤 2. 配置您的 AWS 凭证提供程序”https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md

    AWSSigV4Signer awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials,awsAuthenticationCredentialsProvider);
    request = awsSigV4Signer.sign(request);
    


  • 您的标题应该添加这些信息
    SignedHeaders=host;x-amz-access-token;x- amz-date;x-amz-security-token

    x-amz-access-token: Atza|...
    X-Amz-Security-Token: FwoGZX...
    Host:sellingpartnerapi-na.amazon.com
    X-Amz-Date:20201014T193352Z
    Authorization: AWS4-HMAC-SHA256 Credential=AKIAUEXAMPLE/20201014/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-access-token;x-amz-date;x-amz-security-token, Signature= {your signature}