Skip to content

Commit c127c19

Browse files
committed
add RateLimit
2 parents 3251cbe + 50653b1 commit c127c19

39 files changed

+722
-227
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The purpose of this package is to have an easy way of getting started with the A
3636
- [x] [Reports](https://github.com/amzn/selling-partner-api-docs/blob/main/references/reports-api/reports_2020-09-04.md)
3737
- [x] [FinancesV0](https://github.com/amzn/selling-partner-api-docs/blob/main/references/finances-api/financesV0.md)
3838
- [x] [Feeds](https://github.com/amzn/selling-partner-api-docs/blob/main/references/feeds-api/feeds_2021-06-30.md) for [feedType](https://github.com/amzn/selling-partner-api-docs/blob/main/references/feeds-api/feedtype-values.md) for step to call feed read [doc](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/feeds-api-use-case-guide/feeds-api-use-case-guide_2021-06-30.md)
39-
- [ ] [ListingsItems](https://github.com/amzn/selling-partner-api-docs/blob/main/references/listings-items-api/listingsItems_2021-08-01.md)
39+
- [x] [ListingsItems](https://github.com/amzn/selling-partner-api-docs/blob/main/references/listings-items-api/listingsItems_2021-08-01.md)
4040
- [x] [Uploads](https://github.com/amzn/selling-partner-api-docs/blob/main/references/uploads-api/uploads_2020-11-01.md)
4141
- [x] [shipmentInvoicingV0](https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipment-invoicing-api/shipmentInvoicingV0.md)
4242
- [x] [Shippings](https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md)

Source/FikaAmazonAPI.SampleCode/OrdersSample.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ public OrderList GetOrderListFulfillmentChannels()
114114
{
115115
var parameterOrderList = new ParameterOrderList
116116
{
117-
CreatedAfter = DateTime.UtcNow.AddHours(-24),
118-
FulfillmentChannels = new List<FulfillmentChannels> { FulfillmentChannels.MFN },
119-
OrderStatuses = new List<OrderStatuses> { OrderStatuses.Unshipped, OrderStatuses.Shipped, OrderStatuses.PartiallyShipped }
117+
CreatedAfter = DateTime.UtcNow.AddDays(-24),
118+
//FulfillmentChannels = new List<FulfillmentChannels> { FulfillmentChannels.AFN },
119+
OrderStatuses = new List<OrderStatuses> { OrderStatuses.Shipped}
120120
};
121121

122122
var orders = amazonConnection.Orders.GetOrders(parameterOrderList);

Source/FikaAmazonAPI.SampleCode/Program.cs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Net;
6-
using System.Text;
7-
using System.Threading;
8-
using System.Threading.Tasks;
9-
using FikaAmazonAPI.AmazonSpApiSDK.Api.Sellers;
10-
using FikaAmazonAPI.AmazonSpApiSDK.Clients;
11-
using FikaAmazonAPI;
12-
using FikaAmazonAPI.ConstructFeed;
1+
using FikaAmazonAPI.ConstructFeed;
132
using FikaAmazonAPI.ConstructFeed.Messages;
14-
using FikaAmazonAPI.Parameter;
15-
using FikaAmazonAPI.Parameter.Notification;
16-
using FikaAmazonAPI.Parameter.Order;
17-
using FikaAmazonAPI.Parameter.Report;
18-
using FikaAmazonAPI.Utils;
19-
using static FikaAmazonAPI.ConstructFeed.BaseXML;
20-
using static FikaAmazonAPI.Utils.Constants;
21-
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
22-
using FikaAmazonAPI.AmazonSpApiSDK.Services;
23-
using static FikaAmazonAPI.AmazonSpApiSDK.Models.Token.RestrictedResource;
24-
using FikaAmazonAPI.AmazonSpApiSDK.Models.Reports;
25-
using FikaAmazonAPI.AmazonSpApiSDK.Models.MerchantFulfillment;
263
using FikaAmazonAPI.Parameter.Finance;
4+
using FikaAmazonAPI.Parameter.Order;
275
using FikaAmazonAPI.ReportGeneration;
6+
using FikaAmazonAPI.Utils;
287
using Microsoft.Extensions.Configuration;
29-
using FikaAmazonAPI.Parameter.CatalogItems;
8+
using static FikaAmazonAPI.Utils.Constants;
309

3110
namespace FikaAmazonAPI.SampleCode
3211
{
@@ -52,8 +31,37 @@ static async Task Main(string[] args)
5231
IsActiveLimitRate = true
5332
});
5433

34+
var dataaa = amazonConnection.FbaInventory.GetInventorySummaries(new Parameter.FbaInventory.ParameterGetInventorySummaries
35+
{
36+
granularityType = AmazonSpApiSDK.Models.FbaInventory.Granularity.GranularityTypeEnum.Marketplace,
37+
granularityId = config.GetSection("FikaAmazonAPI:MarketPlaceID").Value
38+
}); ;
39+
40+
ReportManager reportManager = new ReportManager(amazonConnection);
41+
var products = reportManager.GetProducts(); //GET_MERCHANT_LISTINGS_ALL_DATA
42+
var inventoryAging = reportManager.GetInventoryAging(); //GET_FBA_INVENTORY_AGED_DATA
43+
var ordersByDate = reportManager.GetOrdersByOrderDate(90); //GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL
44+
var ordersByLastUpdate = reportManager.GetOrdersByLastUpdate(90); //GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL
45+
var settlementOrder = reportManager.GetSettlementOrder(90); //GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2
46+
var returnMFNOrder = reportManager.GetReturnMFNOrder(90); //GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE
47+
var returnFBAOrder = reportManager.GetReturnFBAOrder(90); //GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA
48+
var reimbursementsOrder = reportManager.GetReimbursementsOrder(180); //GET_FBA_REIMBURSEMENTS_DATA
49+
var feedbacks = reportManager.GetFeedbackFromDays(180); //GET_SELLER_FEEDBACK_DATA
50+
51+
while (true)
52+
{
53+
var data = amazonConnection.ProductPricing.GetItemOffers(new FikaAmazonAPI.Parameter.ProductPricing.ParameterGetItemOffers()
54+
{
55+
ItemCondition = ItemCondition.New,
56+
MarketplaceId = MarketPlace.UnitedArabEmirates.ID,
57+
Asin = "B0010WW4XS"
58+
});
59+
}
60+
61+
62+
5563
OrdersSample ordersSample = new OrdersSample(amazonConnection);
56-
64+
5765
ordersSample.GetOrderListFulfillmentChannels();
5866

5967

@@ -100,16 +108,6 @@ static async Task Main(string[] args)
100108
}
101109

102110

103-
ReportManager reportManager = new ReportManager(amazonConnection);
104-
var products=reportManager.GetProducts(); //GET_MERCHANT_LISTINGS_ALL_DATA
105-
var inventoryAging = reportManager.GetInventoryAging(); //GET_FBA_INVENTORY_AGED_DATA
106-
var ordersByDate = reportManager.GetOrdersByOrderDate(90); //GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL
107-
var ordersByLastUpdate = reportManager.GetOrdersByLastUpdate(90); //GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_GENERAL
108-
var settlementOrder = reportManager.GetSettlementOrder(90); //GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2
109-
var returnMFNOrder = reportManager.GetReturnMFNOrder(90); //GET_FLAT_FILE_RETURNS_DATA_BY_RETURN_DATE
110-
var returnFBAOrder = reportManager.GetReturnFBAOrder(90); //GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA
111-
var reimbursementsOrder = reportManager.GetReimbursementsOrder(180); //GET_FBA_REIMBURSEMENTS_DATA
112-
var feedbacks = reportManager.GetFeedbackFromDays(180); //GET_SELLER_FEEDBACK_DATA
113111

114112

115113
var options = new AmazonSpApiSDK.Models.Feeds.FeedOptions();
@@ -160,7 +158,7 @@ static async Task Main(string[] args)
160158

161159

162160
Console.ReadLine();
163-
161+
164162
}
165163

166164

Source/FikaAmazonAPI.SampleCode/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"FikaAmazonAPI": {
2+
"FikaAmazonAPI_UAE": {
33
"AccessKey": "AKIAXXXXXXXXXXX",
44
"SecretKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXX",
55
"RoleArn": "arn:aws:iam::999999999999:role/USER",

Source/FikaAmazonAPI/AmazonConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using FikaAmazonAPI.Services;
2+
using FikaAmazonAPI.Utils;
23
using System;
4+
using System.Collections.Generic;
35

46
namespace FikaAmazonAPI
57
{

Source/FikaAmazonAPI/AmazonCredential.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
22
using FikaAmazonAPI.Utils;
3+
using System.Collections.Generic;
34
using static FikaAmazonAPI.AmazonSpApiSDK.Models.Token.CacheTokenData;
45
using static FikaAmazonAPI.Utils.Constants;
56

@@ -17,7 +18,7 @@ public class AmazonCredential
1718
private CacheTokenData CacheTokenData { get; set; }
1819
public bool IsActiveLimitRate { get; set; } = true;
1920
public Environments Environment { get; set; } = Environments.Production;
20-
21+
public int MaxThrottledRetryCount { get; set; } = 3;
2122

2223

2324
public AmazonCredential()
@@ -51,5 +52,7 @@ public void SetAWSAuthenticationTokenData(AWSAuthenticationTokenData tokenData)
5152
{
5253
CacheTokenData.SetAWSAuthenticationTokenData(tokenData);
5354
}
55+
internal Dictionary<RateLimitType, RateLimits> UsagePlansTimings { get; set; } = RateLimitsDefinitions.RateLimitsTime;
56+
5457
}
5558
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Runtime/AWSSignerHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ public virtual DateTime InitializeHeaders(IRestRequest restRequest, string host)
184184

185185
DateTime signingDate = DateHelper.GetUtcNow();
186186

187-
restRequest.AddHeader(XAmzDateHeaderName, signingDate.ToString(ISO8601BasicDateTimeFormat, CultureInfo.InvariantCulture));
188-
restRequest.AddHeader(HostHeaderName, host);
187+
restRequest.AddOrUpdateHeader(XAmzDateHeaderName, signingDate.ToString(ISO8601BasicDateTimeFormat, CultureInfo.InvariantCulture));
188+
restRequest.AddOrUpdateHeader(HostHeaderName, host);
189189

190190
return signingDate;
191191
}
@@ -237,7 +237,7 @@ public virtual void AddSignature(IRestRequest restRequest,
237237
authorizationHeaderValueBuilder.AppendFormat(" {0}={1},", SignedHeadersSubHeaderName, signedHeaders);
238238
authorizationHeaderValueBuilder.AppendFormat(" {0}={1}", SignatureSubHeaderName, signature);
239239

240-
restRequest.AddHeader(AuthorizationHeaderName, authorizationHeaderValueBuilder.ToString());
240+
restRequest.AddOrUpdateHeader(AuthorizationHeaderName, authorizationHeaderValueBuilder.ToString());
241241
}
242242

243243
private static string BuildScope(DateTime signingDate, string region)

Source/FikaAmazonAPI/AmazonSpApiSDK/Runtime/Utils.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Globalization;
1+
using System;
2+
using System.Globalization;
23
using System.Net;
34
using System.Security.Cryptography;
45
using System.Text;
@@ -38,7 +39,7 @@ public static string UrlEncode(string data)
3839
/// <returns></returns>
3940
public static string UrlDecode(string data)
4041
{
41-
return WebUtility.UrlDecode(data);
42+
return Uri.UnescapeDataString(data);
4243
}
4344

4445
/// <summary>

Source/FikaAmazonAPI/FikaAmazonAPI.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
<Product>CSharp Amazon Sp API</Product>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
99
<LangVersion>8.0</LangVersion>
10+
<<<<<<< HEAD
1011
<Version>1.1.1</Version>
1112
<AssemblyVersion>1.1.1</AssemblyVersion>
1213
<FileVersion>1.1.1</FileVersion>
14+
=======
15+
<Version>1.1.0-beta</Version>
16+
<AssemblyVersion>1.0.45</AssemblyVersion>
17+
<FileVersion>1.0.45-alpha</FileVersion>
18+
>>>>>>> 50653b10f95a643e4dabb446a9904ab20004dfc1
1319
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1420
<PackageProjectUrl>https://github.com/abuzuhri/Amazon-SP-API-CSharp</PackageProjectUrl>
1521
<PackageLicenseExpression>MIT</PackageLicenseExpression>

Source/FikaAmazonAPI/Services/ApiUrls.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Net;
1+
using System;
2+
using System.Net;
23

34
namespace FikaAmazonAPI.AmazonSpApiSDK.Services
45
{
@@ -251,7 +252,7 @@ public static string GetCompetitivePricing
251252
get => $"{_resourceBaseUrl}/competitivePrice";
252253
}
253254

254-
public static string GetListingOffers(string SellerSKU) => $"{_resourceBaseUrl}/listings/{WebUtility.UrlEncode(SellerSKU)}/offers";
255+
public static string GetListingOffers(string SellerSKU) => $"{_resourceBaseUrl}/listings/{Uri.EscapeDataString(SellerSKU)}/offers";
255256
public static string GetItemOffers(string Asin) => $"{_resourceBaseUrl}/items/{Asin}/offers";
256257

257258
}
@@ -385,7 +386,7 @@ protected class ShipmentInvoicingApiUrls
385386
protected class ProductFeeApiUrls
386387
{
387388
private readonly static string _resourceBaseUrl = "/products/fees/v0";
388-
public static string GetMyFeesEstimateForSKU(string SellerSKU) => $"{_resourceBaseUrl}/listings/{WebUtility.UrlEncode(SellerSKU)}/feesEstimate";
389+
public static string GetMyFeesEstimateForSKU(string SellerSKU) => $"{_resourceBaseUrl}/listings/{Uri.EscapeDataString(SellerSKU)}/feesEstimate";
389390
public static string GetMyFeesEstimateForASIN(string Asin) => $"{_resourceBaseUrl}/items/{Asin}/feesEstimate";
390391
}
391392
protected class TokenApiUrls
@@ -467,13 +468,13 @@ protected class ListingsItemsApiUrls
467468
private readonly static string _resourceBaseUrl = "/listings/2021-08-01";
468469

469470
//https://stackoverflow.com/questions/575440/url-encoding-using-c-sharp/21771206#21771206
470-
public static string GetListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";
471+
public static string GetListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{Uri.EscapeDataString(sku)}";
471472

472-
public static string PutListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";
473+
public static string PutListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{Uri.EscapeDataString(sku)}";
473474

474-
public static string DeleteListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";
475+
public static string DeleteListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{Uri.EscapeDataString(sku)}";
475476

476-
public static string PatchListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";
477+
public static string PatchListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{Uri.EscapeDataString(sku)}";
477478
}
478479

479480
protected class ListingsRestrictionsApi

0 commit comments

Comments
 (0)