文章來源:http://www.samswiches.com/2011/02/how-to-use-amazon-mws-to-download-unshipped-order-reports/
app
After spending many hours trying to understand Amazon’s API for accessing reports, I’ve finally come up with a solution. Below is one way to download an unshipped orders report.this
1 String accessKeyId =
"
YourSecretKey
";
2 String secretAccessKey =
"
YourSecretAccessKey
";
3 MarketplaceWebServiceConfig config =
new MarketplaceWebServiceConfig();
4 config.ServiceURL =
"
https://mws.amazonservices.com
";
5
const
string applicationName =
"
ApplicationName
";
6
const
string applicationVersion =
"
0.1a
";
7
8 MarketplaceWebServiceClient service =
9
new MarketplaceWebServiceClient(
10 accessKeyId,
11 secretAccessKey,
12 applicationName,
13 applicationVersion,
14 config);
15
16
const
string merchantId =
"
YourMerchantID
";
17
const
string marketplaceId =
"
YourMarketplaceID
";
18
19 RequestReportRequest reportRequestRequest =
new RequestReportRequest();
20 reportRequestRequest.Merchant = merchantId;
21 reportRequestRequest.Marketplace = marketplaceId;
22 reportRequestRequest.ReportType =
"
_GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_
";
23
24 RequestReportResponse requestResponse = service.RequestReport(reportRequestRequest);
25 Thread.Sleep(
15000);
//
wait 15 seconds for order to process
26
27 GetReportListRequest listRequest =
new GetReportListRequest();
28 listRequest.Merchant = merchantId;
29 listRequest.Marketplace = marketplaceId;
30 GetReportListResponse listResponse = service.GetReportList(listRequest);
31
32 GetReportListResult getReportListResult = listResponse.GetReportListResult;
33 List<ReportInfo> reportInfoList = getReportListResult.ReportInfo;
34 ReportInfo myReportInfo = reportInfoList[
0];
35
36 GetReportRequest reportRequest =
new GetReportRequest();
37 reportRequest.Merchant = merchantId;
38 reportRequest.Marketplace = marketplaceId;
39
40 String source = path +
"
\\XMLReport.xml
";
41 reportRequest.ReportId = myReportInfo.ReportId;
42 reportRequest.Report = File.Open(source, FileMode.Create, FileAccess.ReadWrite);
43 service.GetReport(reportRequest);
44
45 GetReportRequestListRequest reportRequestListRequest =
new GetReportRequestListRequest();
46 reportRequestListRequest.Marketplace = marketplaceId;
47 reportRequestListRequest.Merchant = merchantId;
48 List<ReportRequestInfo> myListzz =
new List<ReportRequestInfo>();
49
50 GetReportRequestListResponse reportRequestListResponse =
new GetReportRequestListResponse();
51 reportRequestListResponse = service.GetReportRequestList(reportRequestListRequest);
52 GetReportRequestListResult reportRequestListResult =
new GetReportRequestListResult();
53 reportRequestListResult = reportRequestListResponse.GetReportRequestListResult;
54 myListzz = reportRequestListResult.ReportRequestInfo;
55
56
while (myListzz[
0].ReportProcessingStatus.ToString() !=
"
_DONE_
")
57 {
58 lblStatus.Text =
"
Waiting for Report
";
59 Thread.Sleep(
61000);
60 reportRequestListResponse = service.GetReportRequestList(reportRequestListRequest);
61 reportRequestListResult = reportRequestListResponse.GetReportRequestListResult;
62 myListzz = reportRequestListResult.ReportRequestInfo;
63 } spa
Hopefully this example will help others trying to do something similar. Please let me know if you have any questions and I’ll do my best to help.