title: Can extra HTTP headers influence on MWS Feed API submission?
body: <p>It is nasty to debug Amazon MWS Feed submissions because whatever you might be doing wrong Ama just returns the same senseless error message:</p>
  
  <pre><code>&lt;Error&gt;
    &lt;Type&gt;Sender&lt;/Type&gt;
    &lt;Code&gt;InvalidParameterValue&lt;/Code&gt;
    &lt;Message&gt;Either Action or Operation query parameter must be present.&lt;/Message&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p>I am 100% positive that I build StringToSign correctly as well as calculate HMAC-SHA256, etc. It took me a few weeks to collect and adopt a stack of useful functions for hashing, signing, base64ing, etc. MWS requests. Written in pure Pascal they were all tested on Orders and Products APIs.</p>
  
  <p>Now when it comes to Feeds API I am stuck on the above error. All parameters are equal to those generated by MWS Scratchpad. I tested the submission StringToSign generated by MWS Scratchpad, but no luck.</p>
  
  <p>What I noticed so far: there is a difference between the number/values of headers generated by MWS Scratchpad and my app.</p>
  
  <p>The Scratchpad generates the following headers (it least they are displayed):</p>
  
  <pre><code>  Host: mws.amazonservices.ca
    x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript)
    Content-Type: text/xml
  </code></pre>
  
  <p>My app uses Indy (in XE4) TIdHTTP to make a request. When Amazon returns the above error, <code>Request.RawHeaders.Text</code> contains the following:</p>
  
  <pre><code>  Content-Length: 251
    x-amazon-user-agent: MyApp/1.1(Language=Delphi;Platform=Windows7)
    Content-Type: text/xml
    Host: mws.amazonservices.ca
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Encoding: identity
    User-Agent: MyApp/1.1(Language=Delphi;Platform=Windows7)
  </code></pre>
  
  <p>Looks like the extra the headers are added to <code>Request</code> object by default. My first question is: can those extra headers theoretically influence on the behavior? I.e. can they be the showstoppers?</p>
  
  <p>My second question: is there any option to mofidy the list of default heades in Indy <code>HTTP.Request</code>? To go on with the debugging I would rather exclude extra headers to see if the request works.</p>
  
  <p><strong>UPDATE</strong>: (SignedString)</p>
  
  <pre><code>  AWSAccessKeyId=&lt;AWSAccessKeyId&gt;
    &amp;Action=GetFeedSubmissionList
    &amp;Merchant=&lt;MerchantId&gt;
    &amp;SignatureMethod=HmacSHA256
    &amp;SignatureVersion=2
    &amp;Timestamp=2015-07-26T09%3A04%3A59Z
    &amp;Version=2009-01-01
    &amp;Signature=1OI0PVgL3uh5sFXxjCzaaWEwGmW6h5e0dgLUFkPgoXg%3D
  </code></pre>
  
  <p><strong>UPDATE</strong>: (Complete HTTP Request/Response provided by <code>TIdLogFile</code>)</p>
  
  <pre><code>  Stat Connected.
    Sent 28.07.2015 12:28:11:
      POST / HTTP/1.1&lt;EOL&gt;
      Content-Type: text/xml; charset=us-ascii&lt;EOL&gt;
      Content-Length: 279&lt;EOL&gt;
      x-amazon-user-agent: MyAppNameAndVer&lt;EOL&gt;
      Host: mws.amazonservices.ca&lt;EOL&gt;
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;EOL&gt;
      Accept-Encoding: identity&lt;EOL&gt;
      User-Agent: Mozilla/3.0 (compatible; Indy Library)&lt;EOL&gt;&lt;EOL&gt;
  
    Sent 28.07.2015 12:28:11: 
      AWSAccessKeyId=&lt;AWSAccessKeyId&gt;
      &amp;Action=GetFeedSubmissionList
      &amp;MWSAuthToken=&lt;AWSAuthToken&gt;
      &amp;Merchant=&lt;MerchantId&gt;
      &amp;SignatureMethod=HmacSHA256
      &amp;SignatureVersion=2
      &amp;Timestamp=2015-07-28T10%3A28%3A09Z
      &amp;Version=2009-01-01
      &amp;Signature=I6euLIiVDzjZ8bbdtF840K0TJCkGh4NrUbQPtQtu78A%3D
  
    Recv 28.07.2015 12:28:11:
      HTTP/1.1 400 Bad Request&lt;EOL&gt;
      Date: Tue, 28 Jul 2015 10:28:10 GMT&lt;EOL&gt;
      Server: AmazonMWS&lt;EOL&gt;
      x-mws-request-id: 7e63280d-1db5-4d10-af40-587747d032a8&lt;EOL&gt;
      x-mws-timestamp: 2015-07-28T10:28:11.048Z&lt;EOL&gt;
      x-mws-response-context: OmAlguEmW20QT07uIdb9d25xkX+JSS7uFr1rDvXIoqXMvbUFzUMt1b5Xl2WzDaJszbwr25N/J4c=&lt;EOL&gt;
      Content-Type: text/xml&lt;EOL&gt;
      Content-Length: 324&lt;EOL&gt;
      Vary: User-Agent&lt;EOL&gt;
      nnCoection: close&lt;EOL&gt;&lt;EOL&gt;
      &lt;?xml version="1.0"?&gt;&lt;LF&gt;&lt;ErrorResponse xmlns="https://mws.amazonservices.com/"&gt;&lt;LF&gt;  &lt;Error&gt;&lt;LF&gt;    &lt;Type&gt;Sender&lt;/Type&gt;&lt;LF&gt;    &lt;Code&gt;InvalidParameterValue&lt;/Code&gt;&lt;LF&gt;    &lt;Message&gt;Either Action or Operation query parameter must be present.&lt;/Message&gt;&lt;LF&gt;  &lt;/Error&gt;&lt;LF&gt;  &lt;RequestID&gt;7e63280d-1db5-4d10-af40-587747d032a8&lt;/RequestID&gt;&lt;LF&gt;&lt;/ErrorResponse&gt;&lt;LF&gt;
    Stat Disconnected.
  </code></pre>
  
  <p>Please note: I formatted the response for your convenience adding CRs after <code>&lt;EOL&gt;</code></p>
  
  <p>Confusing <code>nnCoection</code> header is explained here: <a href="https://stackoverflow.com/questions/4798461/cneonction-and-nncoection-http-headers">Cneonction and nnCoection HTTP headers</a></p>
  
  <hr>
  
  <p>My question is now resolved. Below is my way to thank people not breaking the Community standards ;-)</p>
  
  <pre><code>Days := 1;
  repeat
    IsSuccessful := DebugAmazonFeedSubmissionProc;
    Inc(Days);
  until IsSuccessful or (Days = 14);
  
  if not IsSuccessful then
  begin
    AskTheGods(@StackOverflow);
    Sleep(1000); // ...wake up and drink a cup'o'tea :)
    Expert := TRemyLebeau.Create('delphi');
    try
      Expert.ReviewTheCode;
      Expert.GetTheJobDone;
    finally
      // You may dispose the instance here,
      // but the Class is one of the most valuable assets of the Community.
      // Thank you, Remy!
    end;
  end;
  </code></pre>