1

通过 Amazon SP API 上传 Feed 有 3 个步骤,第一个是通过createFeedDocumentAPI 获取 Feed 加密信息。但我收到Bad Request以下内容的回应:

{
  "errors": [
    {
      "code": "InvalidInput",
      "message": "Invalid Input",
      "details": ""
    }
  ]
}

C# 代码

        private async Task<IRestResponse> CreateFeedDocument()
        {
            IRestRequest restRequest = new RestRequest("feeds/2020-09-04/documents", Method.POST);
            restRequest.AddParameter("contentType", "application/xml; charset=UTF-8", ParameterType.RequestBody);
            restRequest.AddQueryParameter("MarketplaceIds", "A21TJRUUN4KGV");
            restClient = new RestClient(live_url_base);
            restRequest = await signRequest(restRequest, restClient);
            return restClient.Execute(restRequest);
        }

        private async Task<IRestRequest> signRequest(IRestRequest restRequest, RestClient restClient)
        {
            var roleAcccess = await GetAssumeRoleTokenDetail();
            restRequest.AddHeader("x-amz-access-token", accessToken);

            AWSAuthenticationCredentials AWSCredentials = new AWSAuthenticationCredentials();
            AWSCredentials.AccessKeyId = roleAcccess.Credentials.AccessKeyId;
            AWSCredentials.SecretKey = roleAcccess.Credentials.SecretAccessKey;
            AWSCredentials.Region = region;

            restRequest.AddHeader("X-Amz-Security-Token", roleAcccess.Credentials.SessionToken);
            return new AWSSigV4Signer(AWSCredentials).Sign(restRequest, restClient.BaseUrl.Host);
        }

我怀疑我没有restRequest.AddParameter正确使用,但我不确定。

我一直在关注以下链接:
https ://github.com/amzn/ sell-partner-api-docs/blob/main/references/feeds-api/feeds_2020-09-04.md#createfeeddocument

https://github.com/amzn/ sell-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use- case-guide-2020-09-04.md#step-1-create-a-feed-document

如何使用 .net 在 Amzon 中使用 sell-partner-api 加密和上传数据

更新 我也尝试将下面的行替换
restRequest.AddParameter("contentType", "application/xml; charset=UTF-8", ParameterType.RequestBody);

restRequest.AddJsonBody(new { contentType = "text/xml; charset=UTF-8" });

但后来我收到InvalidSignature如下错误:

{
  "errors": [
    {
      "message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

The Canonical String for this request should have been
'POST
/feeds/2020-09-04/documents

host:sellingpartnerapi-eu.amazon.com
x-amz-access-token:Atza|IwEBIA5KgrCsBbSXHmrXFS_FIgBTInh_xPAydLfi5q2P9xaFQf7p8Zl4NjqhHHxqRzUku__Q7GN1p2WQGRzuAoAa8oMkPLx57NJ05SqxEVXXG-fet3_XgKj8uBCU30HaGPsKltf4g2MD8Pqqt2OUrOXtkv4dAAjjCIxC-bFwVqOhvHktAur--NBv-bJaPZ608Av1GEu96GsNEV9eb0saVBwLaZD7NW3oOjzlCc8GPV9hdqHV5TUXY77QZgBLD1y94Vs1fSo54ShpyoMMOZebzbSr1K5gtf3wJZ.........................{ I hid it }...........................................
x-amz-date:20210524T175148Z
x-amz-security-token:FwoGZXIvYXdzEGsaDNUytY0xuP5/u61APiK2ARMZgv4IT+y2HLzdg5FjZOv6aL2bJ3baJPxBtCY2/7ASntTXfAF5s39P3/qspLLQfmqHPZiMGjweCE3Yf3aW5Q1mt+FLT2s2VUwuOawOQwDll51T2HB3wqyaDOSEpsWeR2Iym4TJXE2hbo7q5CQQBXissOo1Oruk5gcAp7uQHpnyuhCRCkfv/ErEpzdDA0JqfhMxdzmViVgsL1Kzalnbcy9lp+ACI4TL70iOl6j6xkyhFexe/aLXKLLPr4UGMi3Ver2CL6Q4kz.........................{ I hid it }...........................................

host;x-amz-access-token;x-amz-date;x-amz-security-token
4d719849acd655844ab5129f5e54a0ed16954c9580c7a9a737504faf42b309e2'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
20210524T175148Z
20210524/eu-west-1/execute-api/aws4_request
a20e7ffe252dbf98d6a4b9213511ac1918f8bbad75ccbfd7ec46f5c9c1457b08'
",
     "code": "InvalidSignature"
    }
  ]
}

注意:我已经删除了一些尾随字符并放置了......{我隐藏了它}............

4

3 回答 3

1

试试这个

restRequest.AddJsonBody("{\"contentType\":\"text/tab-separated-values; charset=UTF-8\"}");

RestClient restClient = new RestClient("https://sandbox.sellingpartnerapi-eu.amazon.com/");

IRestRequest restRequest = new RestRequest("/feeds/2021-06-30/documents", Method.POST);

restRequest.AddJsonBody("{\"contentType\":\"text/tab-separated-values; charset=UTF-8\"}");
于 2021-07-11T10:27:38.460 回答
0

我在我的开源库中这样做,它的工作没有问题

https://github.com/abuzuhri/Amazon-SP-API-CSharp

这里是创建和提交提要的示例

 ConstructFeedService createDocument = new ConstructFeedService("A3J37AJU4O9RHK", "1.02");

        var list = new List<PriceMessage>();
        list.Add(new PriceMessage()
        {
            SKU = "8201031206122...",
            StandardPrice = new StandardPrice()
            {
                currency = BaseCurrencyCode.AED.ToString(),
                Value = (201.0522M).ToString("0.00")
            }
        });
        createDocument.AddPriceMessage(list);

        var xml = createDocument.GetXML();

        var feedID = amazonConnection.Feed.SubmitFeed(xml, FeedType.POST_PRODUCT_PRICING_DATA);

        Thread.Sleep(1000*30);

        var feedOutput=amazonConnection.Feed.GetFeed(feedID);

        var outPut=amazonConnection.Feed.GetFeedDocument(feedOutput.ResultFeedDocumentId);

        var reportOutpit = outPut.Url;
于 2021-12-08T10:37:24.610 回答
0
private async Task UploadFile(byte[] bytes, string url)
{
  var contentType = "text/plain; charset=utf-8"; // this should be the same as what was used in Step #1 (in the CreateFeedDocument API request)

  RestClient restClient = new RestClient(url);
  IRestRequest restRequest = new RestRequest(Method.PUT);
  restRequest.AddParameter(contentType, bytes, ParameterType.RequestBody);

  var response = await restClient.ExecuteAsync(restRequest);

  if (!response.IsSuccessful)
  {
    // your error logic
  }

  // success. Move to Step #3
}

IllegalLocationConstraintException未指定的位置约束与此请求发送到的区域特定端点不兼容。5B8EGG143CSG45XCi7DqESeN8Q/1QfotMvQIiijcEj/76sr2T+gNh9Ubhq5aQZ7SbZMXCIS/8Mgw6iDod2mCwX/LX6Q=

于 2021-12-10T06:28:07.013 回答