我想要一份所有SKU的清单,其中“起始日期”和“截止日期”与销售数量之间有任何销售。我很困惑该怎么做 - 我应该为此使用亚马逊MWS订单API还是报告API?有没有人有一个c#代码,它显示了如何在我的末端请求和下载报告以进行进一步处理,即将数据保存在数据库中。 任何帮助将非常感激。
P.S。我有大量的数据
更新:同时我编写了这段代码来获取报告类型并保存数据。现在错误是“访问路径被拒绝”
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);
}
任何人都可以检查我的代码并建议这是否是从报告中获取数据的正确方法?我仍然无法保存报告。
更新2
我已经改变了路径,现在错误已经消失并且文件已经创建,但它只是一个包含2条记录的1 kb文件..看起来它没有获取完整数据。不确定代码是否正确。在便笺簿上https://mws.amazonservices.com/scratchpad/index.html
答案 0 :(得分:0)
我会将报告保存在您当前的工作目录中。除非您以管理员身份运行,否则通常会锁定对C:\的访问权限。如果您想要显式,请使用以下内容(如果您只提供文件名而不是完全对齐的路径,它也将保存在您当前的工作目录中)
reportRequest.Report = File.Open(Path.Combine(Directory.GetCurrentDirectory(), "AmazonReport.csv"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
答案 1 :(得分:-1)
在我看来,Orders API会让这更容易。您可以使用日期范围请求订单并获得所需的一切。