问题
I want a list of all SKU for which there were any sales between the From Date and To Date with the quantity sold. I am all confused what to do - should I use Amazon MWS Order API for this or Report API for this? Does anyone have a c# code which shows how a report is requested and downloaded at my end for further processing i.e. saving the data in databases. Any help would be much appreciated.
p.s. I have a large volume of data
UPDATE: Meanwhile I have written this code to get the report type and save the data. Now the error is "Access to path denied"
private const string targetRptType = "_GET_CONVERGED_FLAT_FILE_ORDER_REPORT_DATA_";
try
{
RequestReportRequest reportRequestRequest = new RequestReportRequest();
reportRequestRequest.Merchant = merchantId;
reportRequestRequest.ReportType = targetRptType;
reportRequestRequest.StartDate = DateTime.Now.AddDays(-3);
reportRequestRequest.EndDate = DateTime.Now;
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
config.ServiceURL = "https://mws.amazonservices.com";
MarketplaceWebService.MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config);
RequestReportResponse requestResponse = service.RequestReport(reportRequestRequest);
Thread.Sleep(15000);
Response.Write(requestResponse.RequestReportResult.ReportRequestInfo.ReportProcessingStatus);
GetReportRequestListRequest reportRequestListRequest = new GetReportRequestListRequest();
reportRequestListRequest.Merchant = merchantId;
List<ReportRequestInfo> myListzz = new List<ReportRequestInfo>();
GetReportRequestListResponse reportRequestListResponse = new GetReportRequestListResponse();
reportRequestListResponse = service.GetReportRequestList(reportRequestListRequest);
GetReportRequestListResult reportRequestListResult = new GetReportRequestListResult();
reportRequestListResult = reportRequestListResponse.GetReportRequestListResult;
myListzz = reportRequestListResult.ReportRequestInfo;
while (myListzz[0].ReportProcessingStatus.ToString() != "_DONE_")
{
Thread.Sleep(20000);
reportRequestListResponse = service.GetReportRequestList(reportRequestListRequest);
reportRequestListResult = reportRequestListResponse.GetReportRequestListResult;
myListzz = reportRequestListResult.ReportRequestInfo;
}
GetReportListRequest listRequest = new GetReportListRequest();
listRequest.Merchant = merchantId;
listRequest.ReportRequestIdList = new IdList();
listRequest.ReportRequestIdList.Id.Add(requestResponse.RequestReportResult.ReportRequestInfo.ReportRequestId);
GetReportListResponse listResponse = service.GetReportList(listRequest);
//MessageBox.Show(listResponse.GetReportListResult.ReportInfo.ToString());
GetReportListResult getReportListResult = listResponse.GetReportListResult;
GetReportRequest reportRequest = new GetReportRequest();
reportRequest.Merchant = merchantId;
reportRequest.WithReportId(getReportListResult.ReportInfo[0].ReportId);
GetReportResponse reportResponse = new GetReportResponse();
try
{
reportRequest.Report = File.Open("C:\\AmazonReport.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite); // Getting error access to path denied
reportResponse = service.GetReport(reportRequest);
}
catch (MarketplaceWebServiceException exe)
{
Response.Write(exe);
}
StreamReader sr = new StreamReader(reportRequest.Report);
Response.Write(sr.ReadToEnd());
sr.Close();
}
catch (MarketplaceWebServiceException ex)
{
Response.Write(ex.Message);
}
Can anyone please check my code and suggest if this is the correct way to get data from a report? I am still not able to save the report.
UPDATE 2
I have changed the path and now the error is gone and the file is created but it is just a 1 kb file with 2 records.. looks like it is not fetching full data. Not sure if the code is correct or not. Checking this on scratchpad https://mws.amazonservices.com/scratchpad/index.html
回答1:
I would save the report in your current working directory. Access to C:\ is usually locked down unless you are running as an admin. Use the following if you want to be explicit (if you provide just a file name and not a fully justified path, it will also save in your current working directory)
reportRequest.Report = File.Open(Path.Combine(Directory.GetCurrentDirectory(), "AmazonReport.csv"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
回答2:
The Orders API would make this much easier in my opinion. You can request Orders using a Date range and get everything you need.
来源:https://stackoverflow.com/questions/36168219/amazon-order-api-or-report-api-to-get-sku-number-and-total-quantity-sold