Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MWS GetReport function for the Report API returning a null?

Tags:

c#

amazon-mws

I am trying to pull FBA shipment data report. I have a running application that succesfully pulls Unshipped Orders from Amazon. So bascially I took that code and changed it to what I need it to do for the FBA shipment orders. I barely changed the working code to get a report and now the GetReport function is returning a null and I dont know why. I am passing in a ReportId that is coming from Amazon's system.

If someone could peruse over the code and see if maybe I'm passing in a null object or something.

RequestReportRequest reportRequestRequest = new RequestReportRequest();
reportRequestRequest.Merchant = merchantId;
reportRequestRequest.Marketplace = marketplaceId;
reportRequestRequest.ReportType = "_GET_AMAZON_FULFILLED_SHIPMENTS_DATA_";
reportRequestRequest.StartDate = DateTime.Now.AddDays(-2);
reportRequestRequest.EndDate = DateTime.Now;

RequestReportResponse requestResponse = service.RequestReport(reportRequestRequest);
Thread.Sleep(15000);
Console.WriteLine(requestResponse.RequestReportResult.ReportRequestInfo.ReportProcessingStatus);
GetReportRequestListRequest reportRequestListRequest = new GetReportRequestListRequest();
reportRequestListRequest.Marketplace = marketplaceId;
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.Marketplace = marketplaceId;
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.Marketplace = marketplaceId;
reportRequest.WithReportId(getReportListResult.ReportInfo[0].ReportId);


GetReportResponse reportResponse = new GetReportResponse();

{
    reportResponse = service.GetReport(reportRequest); // <=== ERROR!!!!
}
catch (MarketplaceWebServiceException e)
{
    Console.WriteLine(e);
}
StreamReader sr = new StreamReader(reportRequest.Report);
Console.WriteLine(sr.ReadToEnd());
sr.Close();
like image 485
Lewis Cutter III Avatar asked Feb 24 '23 07:02

Lewis Cutter III


1 Answers

After this line:

GetReportResponse reportResponse = new GetReportResponse(); 

You have to specify a report file, like this:

reportRequest.Report = File.Open("C:\\AmazonReport.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite);

Then, it will write the report to that file. So, you can see your report there.

like image 61
orc_orc Avatar answered Mar 16 '23 06:03

orc_orc