No Report to Download (no data) #164
-
Hello, Is there a better way to check that the report had been completed? The issue we are running into is, if the report completes at Amazon and has no data, then the method below ends up in an infinite loop and never terminates. This is the same code on the "Code" page and works great if there is a file to download. Thank you! ` parameters.marketplaceIds = new MarketplaceIds(); parameters.reportOptions = new FikaAmazonAPI.AmazonSpApiSDK.Models.Reports.ReportOptions(); var reportId = amazonConnection.Reports.CreateReport(parameters); while (string.IsNullOrEmpty(ReportDocumentId)) //filePath for report |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
if you try to use this method CreateReportAndDownloadFile or use the same code will be better way public string CreateReportAndDownloadFile(ReportTypes reportTypes, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null) =>
Task.Run(() => CreateReportAndDownloadFileAsync(reportTypes, dataStartTime, dataEndTime, reportOptions)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportTypes, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null)
{
var parameters = new ParameterCreateReportSpecification();
parameters.reportType = reportTypes;
parameters.marketplaceIds = new MarketplaceIds();
parameters.marketplaceIds.Add(AmazonCredential.MarketPlace.ID);
if (reportOptions != null)
parameters.reportOptions = reportOptions;
if (dataStartTime.HasValue)
parameters.dataStartTime = dataStartTime;
if (dataEndTime.HasValue)
parameters.dataEndTime = dataEndTime;
var reportId = await CreateReportAsync(parameters);
var filePath = string.Empty;
string ReportDocumentId = string.Empty;
while (string.IsNullOrEmpty(ReportDocumentId))
{
var reportData = await GetReportAsync(reportId);
if (!string.IsNullOrEmpty(reportData.ReportDocumentId))
{
filePath = await GetReportFileAsync(reportData.ReportDocumentId);
break;
}
if (reportData.ProcessingStatus == Report.ProcessingStatusEnum.FATAL)
{
throw new Exception("Error with Generate report FATAL");
}
if (reportData.ProcessingStatus == Report.ProcessingStatusEnum.CANCELLED)
{
return null;
}
else Task.Delay(500).Wait();
}
return filePath;
} |
Beta Was this translation helpful? Give feedback.
Hi @feetpeoplellc
if you try to use this method CreateReportAndDownloadFile or use the same code will be better way
Amazon-SP-API-CSharp/Source/FikaAmazonAPI/Services/ReportService.cs
Line 226 in 5b4b30b