Skip to content

Commit 2678cd0

Browse files
committed
fix bug #186
1 parent d4a6b68 commit 2678cd0

File tree

5 files changed

+84
-37
lines changed

5 files changed

+84
-37
lines changed

Source/FikaAmazonAPI.SampleCode/Program.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ static async Task Main(string[] args)
3434
MarketPlace = MarketPlace.GetMarketPlaceByID(config.GetSection("FikaAmazonAPI:MarketPlaceID").Value),
3535
});
3636

37+
DateTime startDate = new DateTime(2021, 10, 03);
38+
var data = amazonConnection.Reports.CreateReportAndDownloadFile(ReportTypes.GET_FBA_REIMBURSEMENTS_DATA, startDate, null, null);
39+
40+
41+
//DateTime startDate = new DateTime(2021, 10, 03);
42+
var data2 = amazonConnection.Reports.CreateReportAndDownloadFile(ReportTypes.GET_EASYSHIP_DOCUMENTS, startDate, null, null);
3743

3844

3945

@@ -189,15 +195,7 @@ static async Task Main(string[] args)
189195
var reimbursementsOrder = reportManager.GetReimbursementsOrder(180); //GET_FBA_REIMBURSEMENTS_DATA
190196
var feedbacks = reportManager.GetFeedbackFromDays(180); //GET_SELLER_FEEDBACK_DATA
191197

192-
while (true)
193-
{
194-
var data = amazonConnection.ProductPricing.GetItemOffers(new FikaAmazonAPI.Parameter.ProductPricing.ParameterGetItemOffers()
195-
{
196-
ItemCondition = ItemCondition.New,
197-
MarketplaceId = MarketPlace.UnitedArabEmirates.ID,
198-
Asin = "B0010WW4XS"
199-
});
200-
}
198+
201199

202200

203201

Source/FikaAmazonAPI.SampleCode/ReportsSample.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Reports;
22
using FikaAmazonAPI.Parameter.Report;
33
using FikaAmazonAPI.Utils;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading;
9-
using System.Threading.Tasks;
104
using static FikaAmazonAPI.Utils.Constants;
115

126
namespace FikaAmazonAPI.SampleCode
@@ -20,7 +14,7 @@ public ReportsSample(AmazonConnection amazonConnection)
2014
}
2115

2216

23-
17+
2418
public void GetReports()
2519
{
2620
var parameters = new ParameterReportList();
@@ -40,7 +34,7 @@ public void GetReportGET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATEs()
4034
parameters.reportTypes.Add(ReportTypes.GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE);
4135
parameters.marketplaceIds = new List<string>();
4236
parameters.marketplaceIds.Add(MarketPlace.UnitedArabEmirates.ID);
43-
var reports=amazonConnection.Reports.GetReports(parameters);
37+
var reports = amazonConnection.Reports.GetReports(parameters);
4438
}
4539

4640
public void CreateReport()
@@ -59,21 +53,21 @@ public void CreateReport()
5953
var reportId = amazonConnection.Reports.CreateReport(parameters);
6054
}
6155

62-
56+
6357
public void GetReport()
6458
{
6559

6660
amazonConnection.Reports.GetReport("192841018867");
6761
}
6862

69-
63+
7064
public void CancelReport()
7165
{
7266

7367
amazonConnection.Reports.CancelReport("192841018867");
7468
}
7569

76-
70+
7771
public void GetReportSchedules()
7872
{
7973

@@ -182,7 +176,7 @@ public string CreateReport_GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE()
182176
filePath = amazonConnection.Reports.GetReportFile(reportData.ReportDocumentId);
183177
break;
184178
}
185-
if(reportData.ProcessingStatus== AmazonSpApiSDK.Models.Reports.Report.ProcessingStatusEnum.FATAL)
179+
if (reportData.ProcessingStatus == AmazonSpApiSDK.Models.Reports.Report.ProcessingStatusEnum.FATAL)
186180
{
187181
throw new Exception("Error with Generate report");
188182
}
@@ -193,9 +187,9 @@ public string CreateReport_GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE()
193187
}
194188

195189

196-
public string CreateReportAndDawnload(ReportTypes reportTypes,DateTime? dataStartTime=null,DateTime? dataEndTime=null, ReportOptions reportOptions=null)
190+
public string CreateReportAndDawnload(ReportTypes reportTypes, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null)
197191
{
198-
return amazonConnection.Reports.CreateReportAndDownloadFile(reportTypes, dataStartTime, dataEndTime, reportOptions);
192+
return amazonConnection.Reports.CreateReportAndDownloadFile(reportTypes, dataStartTime, dataEndTime, reportOptions);
199193
}
200194

201195
public void DownloadExistingReportAndDownloadFile()
@@ -220,6 +214,14 @@ public void GetReportGET_FBA_REIMBURSEMENTS_DATA()
220214
DateTime startDate = new DateTime(2021, 10, 03);
221215
var data = amazonConnection.Reports.CreateReportAndDownloadFile(ReportTypes.GET_FBA_REIMBURSEMENTS_DATA, startDate, null, null);
222216
}
217+
218+
public void GetReportGET_AMAZON_FULFILLED_SHIPMENTS_DATA_INVOICING()
219+
{
220+
DateTime startDate = new DateTime(2021, 10, 03);
221+
var data = amazonConnection.Reports.CreateReportAndDownloadFile(ReportTypes.GET_AMAZON_FULFILLED_SHIPMENTS_DATA_INVOICING, startDate, null, null, true);
222+
}
223+
224+
223225
public void GetReportFile()
224226
{
225227

Source/FikaAmazonAPI/Services/ApiUrls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static string SearchDefinitionsProductTypes
282282
public static string GetDefinitionsProductType(string productType) => $"{_resourceBaseUrl}/productTypes/{productType}";
283283
}
284284

285-
public class ReportApiUrls
285+
protected class ReportApiUrls
286286
{
287287
private readonly static string _resourceBaseUrl = "/reports/2021-06-30";
288288
public static string CreateReport

Source/FikaAmazonAPI/Services/ReportService.cs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Exceptions;
22
using FikaAmazonAPI.AmazonSpApiSDK.Models.Reports;
3+
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
4+
using FikaAmazonAPI.Parameter;
35
using FikaAmazonAPI.Parameter.Report;
4-
using FikaAmazonAPI.Search;
56
using FikaAmazonAPI.Utils;
67
using System;
78
using System.Collections.Generic;
@@ -134,21 +135,42 @@ public async Task<ReportSchedule> GetReportScheduleAsync(string reportScheduleId
134135
return null;
135136
}
136137

137-
public ReportDocument GetReportDocument(string reportDocumentId, IParameterBasedPII parameterBasedPII = null) =>
138-
Task.Run(() => GetReportDocumentAsync(reportDocumentId, parameterBasedPII)).ConfigureAwait(false).GetAwaiter().GetResult();
139-
public async Task<ReportDocument> GetReportDocumentAsync(string reportDocumentId, IParameterBasedPII parameterBasedPII = null)
138+
public ReportDocument GetReportDocument(string reportDocumentId, bool isRestrictedReport = false) =>
139+
Task.Run(() => GetReportDocumentAsync(reportDocumentId, isRestrictedReport)).ConfigureAwait(false).GetAwaiter().GetResult();
140+
public async Task<ReportDocument> GetReportDocumentAsync(string reportDocumentId, bool isRestrictedReport = false)
140141
{
142+
ParameterBasedPII parameterBasedPII = null;
143+
144+
if (isRestrictedReport)
145+
{
146+
parameterBasedPII = new ParameterBasedPII()
147+
{
148+
IsNeedRestrictedDataToken = true,
149+
RestrictedDataTokenRequest = new CreateRestrictedDataTokenRequest
150+
{
151+
restrictedResources = new List<RestrictedResource>
152+
{
153+
new RestrictedResource
154+
{
155+
method = Method.GET.ToString(),
156+
path = ReportApiUrls.GetReportDocument(reportDocumentId)
157+
}
158+
}
159+
}
160+
};
161+
}
162+
141163
await CreateAuthorizedRequestAsync(ReportApiUrls.GetReportDocument(reportDocumentId), RestSharp.Method.GET, parameter: parameterBasedPII);
142164
var response = await ExecuteRequestAsync<ReportDocument>(RateLimitType.Report_GetReportDocument);
143165
if (response != null)
144166
return response;
145167
return null;
146168
}
147-
public string GetReportFile(string reportDocumentId) =>
148-
Task.Run(() => GetReportFileAsync(reportDocumentId)).ConfigureAwait(false).GetAwaiter().GetResult();
149-
public async Task<string> GetReportFileAsync(string reportDocumentId)
169+
public string GetReportFile(string reportDocumentId, bool isRestrictedReport = false) =>
170+
Task.Run(() => GetReportFileAsync(reportDocumentId, isRestrictedReport)).ConfigureAwait(false).GetAwaiter().GetResult();
171+
public async Task<string> GetReportFileAsync(string reportDocumentId, bool isRestrictedReport = false)
150172
{
151-
var reportDocument = await GetReportDocumentAsync(reportDocumentId);
173+
var reportDocument = await GetReportDocumentAsync(reportDocumentId, isRestrictedReport);
152174
return GetFile(reportDocument);
153175
}
154176

@@ -223,12 +245,17 @@ public async Task<bool> CancelReportScheduleAsync(string reportScheduleId)
223245
#endregion
224246

225247

226-
public string CreateReportAndDownloadFile(ReportTypes reportTypes, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null) =>
227-
Task.Run(() => CreateReportAndDownloadFileAsync(reportTypes, dataStartTime, dataEndTime, reportOptions)).ConfigureAwait(false).GetAwaiter().GetResult();
228-
public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportTypes, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null)
248+
public string CreateReportAndDownloadFile(ReportTypes reportType, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null, bool isRestrictedReport = false) =>
249+
Task.Run(() => CreateReportAndDownloadFileAsync(reportType, dataStartTime, dataEndTime, reportOptions, isRestrictedReport)).ConfigureAwait(false).GetAwaiter().GetResult();
250+
public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportType, DateTime? dataStartTime = null, DateTime? dataEndTime = null, ReportOptions reportOptions = null, bool isRestrictedReport = false)
229251
{
252+
if (!isRestrictedReport && Enum.TryParse<RestrictedReportTypes>(reportType.ToString(), out _))
253+
{
254+
isRestrictedReport = true;
255+
}
256+
230257
var parameters = new ParameterCreateReportSpecification();
231-
parameters.reportType = reportTypes;
258+
parameters.reportType = reportType;
232259

233260
parameters.marketplaceIds = new MarketplaceIds();
234261

@@ -251,7 +278,7 @@ public async Task<string> CreateReportAndDownloadFileAsync(ReportTypes reportTyp
251278
var reportData = await GetReportAsync(reportId);
252279
if (!string.IsNullOrEmpty(reportData.ReportDocumentId))
253280
{
254-
filePath = await GetReportFileAsync(reportData.ReportDocumentId);
281+
filePath = await GetReportFileAsync(reportData.ReportDocumentId, isRestrictedReport);
255282
break;
256283
}
257284
if (reportData.ProcessingStatus == Report.ProcessingStatusEnum.FATAL)

Source/FikaAmazonAPI/Utils/Constants.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,26 @@ public enum BuyerType
361361
B2C,
362362
B2B
363363
}
364+
[JsonConverter(typeof(StringEnumConverter))]
365+
public enum RestrictedReportTypes
366+
{
367+
GET_AMAZON_FULFILLED_SHIPMENTS_DATA_INVOICING,
368+
GET_AMAZON_FULFILLED_SHIPMENTS_DATA_TAX,
369+
GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_SHIPPING,
370+
GET_FLAT_FILE_ORDER_REPORT_DATA_SHIPPING,
371+
GET_FLAT_FILE_ORDER_REPORT_DATA_INVOICING,
372+
GET_FLAT_FILE_ORDER_REPORT_DATA_TAX,
373+
GET_FLAT_FILE_ORDERS_RECONCILIATION_DATA_TAX,
374+
GET_FLAT_FILE_ORDERS_RECONCILIATION_DATA_INVOICING,
375+
GET_FLAT_FILE_ORDERS_RECONCILIATION_DATA_SHIPPING,
376+
GET_ORDER_REPORT_DATA_INVOICING,
377+
GET_ORDER_REPORT_DATA_TAX,
378+
GET_ORDER_REPORT_DATA_SHIPPING,
379+
GET_EASYSHIP_DOCUMENTS,
380+
GET_GST_MTR_B2B_CUSTOM,
381+
GET_VAT_TRANSACTION_DATA,
382+
SC_VAT_TAX_REPORT
383+
}
364384

365385
[JsonConverter(typeof(StringEnumConverter))]
366386
public enum ReportTypes

0 commit comments

Comments
 (0)