邮递员-亚马逊MWS-SubmitFeed-您为供稿传递的Content-MD5 HTTP标头不匹配

时间:2020-07-05 16:05:19

标签: post file-upload postman amazon-mws web-api-testing

我正在尝试使用SubmitFeed网络服务通过POSTMAN应用程序将产品上传到Amazon。

我使用Amazon MWS Scratchpad测试了我的请求,该请求有效。但是,当我尝试从POSTMAN发出相同请求时,收到ContentMD5DoesNotMatch错误。

我计算出的MD5值与MD5值Amazon MWS Scratchpad相同。因此,我认为在上传文件时会遇到一些问题。

我想念什么?

这是file.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
  <Header>
    <DocumentVersion>1.01</DocumentVersion>
    <MerchantIdentifier>M_EXAMPLE_123456</MerchantIdentifier>
  </Header>
  <MessageType>Product</MessageType>
  <PurgeAndReplace>false</PurgeAndReplace>
  <Message>
    <MessageID>1</MessageID>
    <OperationType>Update</OperationType>
    <Product>
      <SKU>56789</SKU>
      <StandardProductID>
        <Type>ASIN</Type>
        <Value>B0EXAMPLEG</Value>
      </StandardProductID>
      <ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
      <DescriptionData>
        <Title>Example Product Title</Title>
        <Brand>Example Product Brand</Brand>
        <Description>This is an example product description.</Description>
        <BulletPoint>Example Bullet Point 1</BulletPoint>
        <BulletPoint>Example Bullet Point 2</BulletPoint>
        <MSRP currency="USD">25.19</MSRP>
        <Manufacturer>Example Product Manufacturer</Manufacturer>
        <ItemType>example-item-type</ItemType>
      </DescriptionData>
      <ProductData>
        <Health>
          <ProductType>
            <HealthMisc>
              <Ingredients>Example Ingredients</Ingredients>
              <Directions>Example Directions</Directions>
            </HealthMisc>
          </ProductType>
        </Health>
      </ProductData>
    </Product>
  </Message>
</AmazonEnvelope>

这是我的请求和回复的正文:

enter image description here

这是我的请求前脚本:

var HTTPVerb = "POST";
var ValueOfHostHeaderInLowercase = "https://mws-eu.amazonservices.com"; 
var HTTPRequestURI = "/";

var TimeStamp = encodeURIComponent(new Date().toISOString());

var ContentMD5Value = "7iiKpIWEgdex10Isb8Szrw=="; //I wrote it here hardcoded here, to be sure.

var CanonicalizedQueryString = 
"AWSAccessKeyId=" + "***" +
"&Action=" + "SubmitFeed" +
"&ContentMD5Value=" + encodeURIComponent(ContentMD5Value) +
"&FeedType=" + "_POST_PRODUCT_DATA_" +
"&MWSAuthToken=" + "***" +
"&MarketplaceIdList.Id.1=" + "***" +
"&Merchant=" + "***" +
"&PurgeAndReplace=" + "false" + 
"&SignatureMethod=" + "HmacSHA256" +
"&SignatureVersion=" + "2" +
"&Timestamp=" + TimeStamp +
"&Version=" + "2009-01-01";

var StringToSign = HTTPVerb + "\n" +
  "mws-eu.amazonservices.com" + "\n" +
  HTTPRequestURI + "\n" +
  CanonicalizedQueryString;

let hash = CryptoJS.HmacSHA256(StringToSign, '***');
let Signature = (CryptoJS.enc.Base64.stringify(hash));

var PostQueryString = 
"AWSAccessKeyId=" + "***" +
"&Action=" + "SubmitFeed" +
"&Merchant=" + "***" +
"&MWSAuthToken=" + "***" +
"&SignatureVersion=" + "2" +
"&Timestamp=" + TimeStamp +
"&Version=" + "2009-01-01" +
"&ContentMD5Value=" + encodeURIComponent(ContentMD5Value) +
"&Signature=" + encodeURIComponent(Signature) + 
"&SignatureMethod=" + "HmacSHA256" +
"&FeedType=" + "_POST_PRODUCT_DATA_" +
"&MarketplaceIdList.Id.1=" + "***" +
"&PurgeAndReplace=" + "false"
;

pm.environment.set('AmazonHost', ValueOfHostHeaderInLowercase + HTTPRequestURI + '?' + PostQueryString);

1 个答案:

答案 0 :(得分:0)

我们无法确定您遇到的问题,但是大多数情况下,出现此问题是由于缺少参数或某些参数(例如FeedType中未定义或值为空)。< / p>

我在程序中打印我的规范化字符串,并将其与mws-scratchpad的请求详细信息中的String to Sign进行比较。