Skip to content

Commit 79cf312

Browse files
committed
add new report enum
1 parent 46bcc36 commit 79cf312

File tree

5 files changed

+116
-11
lines changed

5 files changed

+116
-11
lines changed

Source/FikaAmazonAPI.Sample/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static async Task Main(string[] args)
3030
{
3131

3232

33-
3433
AmazonConnection amazonConnection = new AmazonConnection(new AmazonCredential()
3534
{
3635
AccessKey = Environment.GetEnvironmentVariable("AccessKey"),
@@ -44,12 +43,14 @@ static async Task Main(string[] args)
4443

4544
}) ;
4645

47-
ReportsSample reportsSample = new ReportsSample(amazonConnection);
48-
reportsSample.GetReportGET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATEs();
49-
reportsSample.CreateReport_GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE();
46+
//ReportsSample reportsSample = new ReportsSample(amazonConnection);
47+
48+
//reportsSample.GetReportGET_FBA_REIMBURSEMENTS_DATA();
49+
//reportsSample.GetReportGET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATEs();
50+
//reportsSample.CreateReport_GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE();
5051

51-
FeedsSample feedsSample = new FeedsSample(amazonConnection);
52-
//feedsSample.SubmitFeedInventory();
52+
//FeedsSample feedsSample = new FeedsSample(amazonConnection);
53+
////feedsSample.SubmitFeedInventory();
5354

5455

5556
amazonConnection.ProductFee.GetMyFeesEstimateForSKU("SKU1 + SKU2-FBA",

Source/FikaAmazonAPI.Sample/ReportsSample.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FikaAmazonAPI.Parameter.Report;
1+
using FikaAmazonAPI.AmazonSpApiSDK.Models.Reports;
2+
using FikaAmazonAPI.Parameter.Report;
23
using FikaAmazonAPI.Utils;
34
using System;
45
using System.Collections.Generic;
@@ -191,6 +192,54 @@ public string CreateReport_GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE()
191192
return filePath;
192193
}
193194

195+
196+
public string CreateReportAndDawnload(ReportTypes reportTypes,DateTime? dataStartTime=null,DateTime? dataEndTime=null, ReportOptions reportOptions=null)
197+
{
198+
199+
var parameters = new ParameterCreateReportSpecification();
200+
parameters.reportType = reportTypes;
201+
202+
parameters.marketplaceIds = new MarketplaceIds();
203+
parameters.marketplaceIds.Add(MarketPlace.UnitedArabEmirates.ID);
204+
205+
if(reportOptions!=null)
206+
parameters.reportOptions = reportOptions;
207+
208+
if(dataStartTime.HasValue)
209+
parameters.dataStartTime = dataStartTime;
210+
if(dataEndTime.HasValue)
211+
parameters.dataEndTime = dataEndTime;
212+
213+
var reportId = amazonConnection.Reports.CreateReport(parameters);
214+
var filePath = string.Empty;
215+
string ReportDocumentId = string.Empty;
216+
217+
while (string.IsNullOrEmpty(ReportDocumentId))
218+
{
219+
var reportData = amazonConnection.Reports.GetReport(reportId);
220+
if (!string.IsNullOrEmpty(reportData.ReportDocumentId))
221+
{
222+
filePath = amazonConnection.Reports.GetReportFile(reportData.ReportDocumentId);
223+
break;
224+
}
225+
if (reportData.ProcessingStatus == AmazonSpApiSDK.Models.Reports.Report.ProcessingStatusEnum.FATAL)
226+
{
227+
throw new Exception("Error with Generate report");
228+
}
229+
else Thread.Sleep(1000 * 60);
230+
}
231+
232+
return filePath;
233+
}
234+
235+
236+
237+
public void GetReportGET_FBA_REIMBURSEMENTS_DATA()
238+
{
239+
DateTime startDate = new DateTime(2021, 10, 03);
240+
DateTime endDate = new DateTime(2021, 10, 10);
241+
var reportPath = amazonConnection.Reports.CreateReportAndDownloadFile(ReportTypes.GET_FBA_REIMBURSEMENTS_DATA, startDate, endDate);
242+
}
194243
public void GetReportFile()
195244
{
196245

Source/FikaAmazonAPI/FikaAmazonAPI.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
54
<PackageId>CSharpAmazonSpAPI</PackageId>
65
<Authors>Tareq Abuzuhri</Authors>
76
<Company>Cozly AB</Company>
87
<Product>CSharp Amazon Sp API</Product>
98
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
109
<LangVersion>8.0</LangVersion>
11-
<Version>1.0.21</Version>
12-
<AssemblyVersion>1.0.1.21</AssemblyVersion>
13-
<FileVersion>1.0.1.21</FileVersion>
10+
<Version>1.0.22</Version>
11+
<AssemblyVersion>1.0.1.22</AssemblyVersion>
12+
<FileVersion>1.0.1.22</FileVersion>
1413
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1514
<PackageProjectUrl>https://github.com/abuzuhri/Amazon-SP-API-CSharp</PackageProjectUrl>
1615
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -22,6 +21,7 @@
2221
<Description>.Net C# library for the new Amazon Selling Partner API</Description>
2322
<RepositoryType>git</RepositoryType>
2423
<PackageIcon>icon.jpg</PackageIcon>
24+
<TargetFramework>netstandard2.0</TargetFramework>
2525

2626
</PropertyGroup>
2727
<ItemGroup>

Source/FikaAmazonAPI/Services/ReportService.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using System.Collections.Generic;
99
using System.IO;
1010
using System.Text;
11+
using System.Threading;
12+
using static FikaAmazonAPI.Utils.Constants;
1113

1214
namespace FikaAmazonAPI.Services
1315
{
@@ -189,5 +191,52 @@ public bool CancelReportSchedule(string reportScheduleId)
189191
return true;
190192
}
191193
#endregion
194+
195+
196+
public string CreateReportAndDownloadFile(ReportTypes reportTypes, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null)
197+
{
198+
199+
var parameters = new ParameterCreateReportSpecification();
200+
parameters.reportType = reportTypes;
201+
202+
parameters.marketplaceIds = new MarketplaceIds();
203+
204+
parameters.marketplaceIds.Add(this.MarketPlace.ID);
205+
206+
if (reportOptions != null)
207+
parameters.reportOptions = reportOptions;
208+
209+
if (dataStartTime.HasValue)
210+
parameters.dataStartTime = dataStartTime;
211+
if (dataEndTime.HasValue)
212+
parameters.dataEndTime = dataEndTime;
213+
214+
var reportId = CreateReport(parameters);
215+
var filePath = string.Empty;
216+
string ReportDocumentId = string.Empty;
217+
218+
while (string.IsNullOrEmpty(ReportDocumentId))
219+
{
220+
var reportData = GetReport(reportId);
221+
if (!string.IsNullOrEmpty(reportData.ReportDocumentId))
222+
{
223+
filePath = GetReportFile(reportData.ReportDocumentId);
224+
break;
225+
}
226+
if (reportData.ProcessingStatus == Report.ProcessingStatusEnum.FATAL)
227+
{
228+
throw new Exception("Error with Generate report FATAL");
229+
}
230+
if (reportData.ProcessingStatus == Report.ProcessingStatusEnum.CANCELLED)
231+
{
232+
throw new Exception("Error with Generate report CANCELLED");
233+
}
234+
else Thread.Sleep(1000 * 60);
235+
}
236+
237+
return filePath;
238+
}
239+
240+
192241
}
193242
}

Source/FikaAmazonAPI/Utils/Constants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ public enum ReportTypes
437437
GET_FLAT_FILE_OFFAMAZONPAYMENTS_SANDBOX_SETTLEMENT_DATA,
438438
GET_B2B_PRODUCT_OPPORTUNITIES_RECOMMENDED_FOR_YOU,
439439
GET_B2B_PRODUCT_OPPORTUNITIES_NOT_YET_ON_AMAZON,
440+
GET_BRAND_ANALYTICS_MARKET_BASKET_REPORT,
441+
GET_BRAND_ANALYTICS_SEARCH_TERMS_REPORT,
442+
GET_BRAND_ANALYTICS_REPEAT_PURCHASE_REPORT,
443+
GET_BRAND_ANALYTICS_ALTERNATE_PURCHASE_REPORT,
444+
GET_BRAND_ANALYTICS_ITEM_COMPARISON_REPORT,
445+
440446

441447
}
442448
[JsonConverter(typeof(StringEnumConverter))]

0 commit comments

Comments
 (0)