Amazon MWS (PHP) - How does the request work
amazon-mws, php
Solution
The answer to your question comes in two parts.
Part 1 - Calling the Amazon API
Most MWS requests do not require any file (be it plain text or XML) to be sent to Amazon. For example, all parameters needed to do send `RequestReport` can (and must) be sent as regular parameters. I'm not sure what Amazon would do if you did submit a file along with it as I've never tried. But then again... why would you?
One of the calls that does require a file to be send is the `SubmitFeed` call where that file is the actual feed to be submitted. It depends on the type of feed you're submitting if Amazon expects it to be plain text or XML.
Part 2 - Handling Amazon's API responses
When you get information back from Amazon's API, it usually is in XML format (there are a few calls that may return plaintext instead). You will need to decode this data to get your information out.
To make it a bit clearer, I'll outline a typical process for you:
The process of getting all your listings from Amazon:
- Do a `RequestReport` call to Amazon. No XML attached
Decode the XML that you're getting back (it is a `RequestReportResponse`). If all went well, you'll get a `RequestReportId` as part of the response, and Amazon will start processing your request.
Amazon may need a few minutes to actually create the report, in cases of very complex or large requests or during high activity hours it may actually take up to an hour or more. So we need to find out when the request we made is actually done.
Poke Amazon API with a `GetReportRequestList` call asking for the status of your request with `ReportRequestIdList.Id.1={YourRequestIdHere}`. This also does not need a XML attachment.
Decode the XML that you're getting back. (it is a `GetReportRequestListResponse`)
If its `ReportProcessingStatus` is not `_DONE_`, wait for at least 45 seconds, then repeat from step 3. If the report is actually done, you'll see a valid `GeneratedReportId` in the response. If it is missing, you'll need to do an extra `GetReportList` call to find its ID.
Call `GetReport` to finally fetch your report with `ReportId={YourGeneratedReportIdHere}`
Decode whatever you're getting back. Depending on the type of report you requested, the response may be XML or plain text.
This process is explained in detail (and with a pretty flow chart) in Amazon Marketplace Web Service Reports API Section Reference (Version 2009-01-01)
To finally answer your question with respect to getting active listings from Amazon MWS: None of the three calls require you to send XML to Amazon. The data you receive from Amazon will be in XML format (with the possible exception step 6 if you requested a plain text report).
Problem
I am trying to pull a report in PHP for active listings. I've made progress, however, I cannot understand how this works and there is nothing out there that can explain it. For example, in the Samples provided from the PHP library, I see quite a few XML files. When you run the `RequestReportResponse` sample, does that generate the XML file, or does the XML file tell the `RequestReportResponse` what to do based on values and functions? I am asking because, with the MWS Scratchpad - I select all the necessary fields, submit it then refresh the Amazon Reports page of my seller central section and it shows a pending report. I'm just asking how the XML content affects the report or how the report can affect the XML.