ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Amazon Marketplace Web Services (MWS)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Amazon Marketplace Web Services (MWS)

    Just wondering if anyone has worked succesfully with the Amazon MWS. Specifically, I've been asked to interface with the Orders APIs (to get orders), and the "Submit Feed" API (to send Order Acknowledgement/Fulfillment data as well as inventory levels). I'm hoping I can accomplish this with HTTPAPI.

    They seem fairly simliar to APIs I've worked with in the past, except that the "Feeds" require Content-MD5 Headers

    Here is a sample from their API reference.
    Code:
    POST /?AWSAccessKeyId=0PB842ExampleN4ZTR2
    &Action=SubmitFeed
    &FeedType=_POST_PRODUCT_DATA_
    &MWSAuthToken=amzn.mws.4ea38b7b-f563-7709-4bae-87aeaEXAMPLE
    &MarketplaceIdList.Id.1=ATVExampleDER
    &SellerId=A1XExample5E6
    &SignatureMethod=HmacSHA256
    &SignatureVersion=2
    &Timestamp=2009-01-26T23%3A51%3A31.315Z
    &Version=2009-01-01
    &Signature=SvSExamplefZpSignaturex2cs%3D HTTP/1.1
    Content-MD5: ExampleMd5HashOfHttpBodyAsPerRfc2616Example
    Content-Type: text/xml; charset=iso-8859-1
    Host: mws.amazonservices.com
    User-Agent: <Your User Agent Header>
    Any suggestions and/or caveat would be appreciated.
    Thx,
    Greg

  • #2
    I've done one project that accessed Amazon MWS, Greg. HTTPAPI did everything I needed it to do. If you have specific questions or run into trouble, please email me thru the itjungle.com contacts page,

    Ted

    Comment


    • #3
      HTTPAPI does not automatically set the content-md5 header. Did you add code for that, Ted? Or did Amazon accept the request without it?

      Comment


      • #4
        Originally posted by Scott Klement View Post
        HTTPAPI does not automatically set the content-md5 header. Did you add code for that, Ted? Or did Amazon accept the request without it?
        I was wondering the same thing...

        I'm assuming I would have to
        1. Use the WebForm methodolgy to create the variables in the query string
        2. Create the content-md5 hash (I saw a post on this forum about this)
        3. Then add the content-md5 header using the HTTPAPI exit procedure http_xproc

        Comment


        • #5
          I used Qc3CalculateHMAC to generate the signature.

          Comment


          • #6
            Originally posted by Scott Klement View Post
            HTTPAPI does not automatically set the content-md5 header. Did you add code for that, Ted? Or did Amazon accept the request without it?
            I'm still struggling to understand these web services, the MD5 hash etc.
            Scott - you showed me before how to add headers using HTTPAPI - so I think I can do that.

            My problem is understanding the "Signature" and the "Content-MD5" header. In looking at http_debug.txt, i can see that I do not have "Content-MD5" and "Content-type" are not present.

            The MWS scratchpad gives me a "string to sign" which I can match... It also provides the "Post Data" along with two other values: "SHA 256 HMAC" and "Base64 HMAC". I believe the latter is the Signature value from my original post. But I'm not sure how to calcuate the value for "Content-MD5" in the header.

            When I post (without the Content-MD5 in the header), I receive: "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."

            Comment


            • #7
              Maybe you forgot to convert the data to ASCII or UTF-8 (or whatever this server expects) before generating the MD5? Obviously if your MD5 is generated on EBCDIC data and theirs is on ASCII data, they will not match.

              Comment


              • #8
                I was converting to ASCII... my problem was more bonehead that that... I was generating the MD5 from a string beginning with "POST" then using http_url_get. After changing my string from POST to GET, I could connect just fine (alternativley, I could use to http_url_post).
                Code:
                 [SIZE=2]String [/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'POST'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]+[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] LF [/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]+ [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'mws.amazonservices.com'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]+[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] LF +[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/Orders/2013-09-01'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080] ...[/COLOR][/SIZE][/COLOR][/SIZE]
                rc = http_url_post(...
                I did NOT have to add the Content-MD5 header. I added the MD5 to the end of the query string in the &Signature variable.

                The documentation for MWS is very detailed, but contains some discrepancies.

                Comment


                • #9
                  gwilburn - would you mind pointing me to the MWS documentation, as I am tasked with creating an AWS for encryption on our ibm i.
                  Any pointers for someone getting started? I have experience with webservice from rpg using both http_api and systools.

                  Comment


                  • #10
                    Jay - Sorry, I was on vacation last week. Yes, I did get this working for our purposes (APIs for Getting orders, updating inventory levels, updating orders as shipped). There are so many different APIs, but they all work basically the same. The key to all of them is calculating the MD5 Hash correctly and using the Amazon Scratchpad to test/verify.

                    I only implemented the Feeds API (SubmitFeed operation) and Orders API (ListOrders, ListOrderItems, and each of those ...byNextToken)

                    I used Scott's HTTPAPI, BASE64, and WEBFORMS to build my strings and do the conversion to ASCII
                    I used Qc3CalculateHMAC (IBM API) as Ted indicated above.
                    I also used Qc3CalculateHash (IBM API) for the "Content MD5 Value" used in the SubmitFeed operation. When posting XML data stored in a streamfile (inventory levels), you have to also calculate the MD5 for the XML content.

                    Key points:
                    1. Build your parameter strings (keywords & variables) in ascending order (numbers, upper, then lower) - it all has to be in the same order as you see in the scratchpad - even the line feeds
                    2. Convert your string-to-sign to ASCII before calculating the MD5 - again, the scratchpad will show you this
                    3. Be sure to use a timestamp as indicated - I had to write something to create a 20-char representation of the current zulu time by calling CEEUTC and CEEDATM (there is an example on this forum somewhere)

                    I can't stress enough how important it is to use the scratchpad.

                    Here are some documentation links that I found helpful:





                    This is the scratchpad:


                    I hope that helps!
                    Greg


                    Comment


                    • #11
                      Hi Greg - I need to do something very similar. Is there any chance you'd be willing to share code examples? Thanks!

                      Comment

                      Working...
                      X