Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Amazon-SP-API-CSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FikaAmazonAPI.SampleCode",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FikaAmazonAPI", "Source\FikaAmazonAPI\FikaAmazonAPI.csproj", "{D6BE954D-174D-4C19-A0B6-46F020878E72}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Source\Tests\Tests.csproj", "{4CB44101-8A9E-454A-B272-038C5FAF9F23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,18 +32,13 @@ Global
{D6BE954D-174D-4C19-A0B6-46F020878E72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6BE954D-174D-4C19-A0B6-46F020878E72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6BE954D-174D-4C19-A0B6-46F020878E72}.Release|Any CPU.Build.0 = Release|Any CPU
{4CB44101-8A9E-454A-B272-038C5FAF9F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CB44101-8A9E-454A-B272-038C5FAF9F23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CB44101-8A9E-454A-B272-038C5FAF9F23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CB44101-8A9E-454A-B272-038C5FAF9F23}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FC494085-19C4-4835-B053-F9B74FFB978A} = {3472E85C-6C29-4196-AA16-B95898241C04}
{D6BE954D-174D-4C19-A0B6-46F020878E72} = {3472E85C-6C29-4196-AA16-B95898241C04}
{4CB44101-8A9E-454A-B272-038C5FAF9F23} = {3472E85C-6C29-4196-AA16-B95898241C04}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F072E7DD-BF35-43CC-BF83-E5947CA2D772}
Expand Down
34 changes: 0 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,41 +120,7 @@ AmazonConnection amazonConnection = new AmazonConnection(new AmazonCredential()

```

### Multithreaded connections
If multithreading, the following should be done to avoid inadvertantly passing incorrect token data between different threads:
```CSharp

// Note - you may also write and pass your own implementation of the IRateLimitingHandler interface if required

var connectionFactory = new AmazonMultithreadedConnectionFactory(
ClientId: "amzn1.application-XXX-client.XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
ClientSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
RefreshToken: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
// a singleton that handles rate limiting across multiple threads
rateLimitingHandler: new RateLimitingHandler());

// Then in each concurrent thread/request scope, a new connection can be created like so
var amazonConnection = connectionFactory.RequestScopedConnection(
marketPlaceId: "A2VIGQ35RCS4UG",
sellerId: "MySellerId",
// credentialConfiguration is an optional parameter that allows additional configuration of the AmazonCredential
credentialConfiguration: cred =>
{
cred.IsActiveLimitRate = true;
cred.IsDebugMode = true;
});

// or (remember either Marketplace OR Marketplace ID must be provided)
var amazonConnection = connectionFactory.RequestScopedConnection(
sellerId: "MySellerId",
credentialConfiguration: cred =>
{
cred.IsActiveLimitRate = true;
cred.IsDebugMode = true;
cred.Marketplace = MarketPlace.UnitedArabEmirates
});

```

### Configuration using a proxy
Please see [here](https://github.com/abuzuhri/Amazon-SP-API-CSharp/blob/main/Source/FikaAmazonAPI.SampleCode/Program.cs) for the relevant code file.
Expand Down
48 changes: 21 additions & 27 deletions Source/FikaAmazonAPI.SampleCode/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.FbaSmallandLight;
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.SampleCode
{
Expand All @@ -14,32 +13,27 @@ static async Task Main(string[] args)
.AddUserSecrets<Program>()
.Build();

var connectionFactory = new AmazonMultithreadedConnectionFactory(
ClientId: config.GetSection("FikaAmazonAPI:ClientId").Value,
ClientSecret: config.GetSection("FikaAmazonAPI:ClientSecret").Value,
RefreshToken: config.GetSection("FikaAmazonAPI:RefreshToken").Value,
rateLimitingHandler: new RateLimitingHandler());
var factory = LoggerFactory.Create(builder => builder.AddConsole());

var tasks = Enumerable.Range(1, 10).Select(x =>
Task.Run(() =>
AmazonConnection amazonConnection = new AmazonConnection(new AmazonCredential()
{
var amazonConnection = connectionFactory.RequestScopedConnection(
marketPlaceId: config.GetSection("FikaAmazonAPI:MarketPlaceID").Value,
sellerId: config.GetSection("FikaAmazonAPI:SellerId").Value,
credentialConfiguration: cred =>
{
cred.IsActiveLimitRate = true;
cred.IsDebugMode = true;
});

ReportManagerSample reportManagerSample = new ReportManagerSample(amazonConnection);
reportManagerSample.CallReport();
}));

await Task.WhenAll(tasks);

//var loggingExamples = new SerilogLoggingExamples(config);
//await loggingExamples.ConsoleLoggerExample();
ClientId = config.GetSection("FikaAmazonAPI:ClientId").Value,
ClientSecret = config.GetSection("FikaAmazonAPI:ClientSecret").Value,
RefreshToken = config.GetSection("FikaAmazonAPI:RefreshToken").Value,
MarketPlaceID = config.GetSection("FikaAmazonAPI:MarketPlaceID").Value,
SellerID = config.GetSection("FikaAmazonAPI:SellerId").Value,
IsDebugMode = true
}, loggerFactory: factory);


ReportManagerSample reportManagerSample = new ReportManagerSample(amazonConnection);
reportManagerSample.CallReport();
//var error = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_STRANDED_INVENTORY_UI_DATA);
//var dddd = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_FBA_MYI_ALL_INVENTORY_DATA);
//var dddd = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA);
//ReportManager reportManager = new ReportManager(amazonConnection);

//var dddddd = reportManager.GetAFNInventoryQtyAsync().ConfigureAwait(false).GetAwaiter().GetResult();

Console.ReadLine();

Expand Down
66 changes: 31 additions & 35 deletions Source/FikaAmazonAPI/AmazonConnection.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.Exceptions;
using FikaAmazonAPI.Services;
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Logging;
using System;
using System.Globalization;
using System.Threading;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI
{
public class AmazonConnection
{
private readonly ILoggerFactory _loggerFactory;
private AmazonCredential Credentials { get; set; }

private IRateLimitingHandler RateLimitingHandler { get; }

public AppIntegrationsServiceV20240401 AppIntegrationsServiceV20240401 => this._AppIntegrationsServiceV20240401 ?? throw _NoCredentials;
public OrderService Orders => this._Orders ?? throw _NoCredentials;
public ReportService Reports => this._Reports ?? throw _NoCredentials;
Expand Down Expand Up @@ -95,12 +92,11 @@
private UnauthorizedAccessException _NoCredentials = new UnauthorizedAccessException($"Error, you cannot make calls to Amazon without credentials!");

public string RefNumber { get; set; }
public AmazonConnection(AmazonCredential Credentials, IRateLimitingHandler rateLimitingHandler = null, string RefNumber = null, CultureInfo? cultureInfo = null, ILoggerFactory? loggerFactory = null)
public AmazonConnection(AmazonCredential Credentials, string RefNumber = null, CultureInfo? cultureInfo = null, ILoggerFactory? loggerFactory = null)

Check warning on line 95 in Source/FikaAmazonAPI/AmazonConnection.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 95 in Source/FikaAmazonAPI/AmazonConnection.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
_loggerFactory = loggerFactory;
this.Authenticate(Credentials);
this.RefNumber = RefNumber;
this.RateLimitingHandler = rateLimitingHandler ?? new RateLimitingHandler();
Thread.CurrentThread.CurrentCulture = cultureInfo ?? CultureInfo.CurrentCulture;
}

Expand All @@ -127,35 +123,35 @@
this._CatalogItems = new CatalogItemService(this.Credentials, _loggerFactory);
this._ProductPricing = new ProductPricingService(this.Credentials, _loggerFactory);

this._FbaInbound = new FbaInboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaInventory = new FbaInventoryService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaOutbound = new FbaOutboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaSmallandLight = new FbaSmallandLightService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaInboundEligibility = new FbaInboundEligibilityService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._EasyShip20220323 = new EasyShip20220323Service(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._AplusContent = new AplusContentService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Feed = new FeedService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ListingsItem = new ListingsItemService(this.Credentials, _loggerFactory, this.RateLimitingHandler );
this._Restrictions = new RestrictionService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._MerchantFulfillment = new MerchantFulfillmentService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Messaging = new MessagingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Notification = new NotificationService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ProductFee = new ProductFeeService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ProductType = new ProductTypeService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Sales = new SalesService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Seller = new SellerService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Services = new ServicesService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ShipmentInvoicing = new ShipmentInvoicingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Shipping = new ShippingService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._ShippingV2 = new ShippingServiceV2(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Upload = new UploadService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._Tokens = new TokenService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FulFillmentInbound = new FulFillmentInboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FulFillmentInboundv20240320 = new FulFillmentInboundServicev20240320(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FulFillmentOutbound = new FulFillmentOutboundService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._VendorOrders = new VendorOrderService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._VendorTransactionStatus = new VendorTransactionStatusService(this.Credentials, _loggerFactory, this.RateLimitingHandler);
this._FbaInbound = new FbaInboundService(this.Credentials, _loggerFactory);
this._FbaInventory = new FbaInventoryService(this.Credentials, _loggerFactory);
this._FbaOutbound = new FbaOutboundService(this.Credentials, _loggerFactory);
this._FbaSmallandLight = new FbaSmallandLightService(this.Credentials, _loggerFactory);
this._FbaInboundEligibility = new FbaInboundEligibilityService(this.Credentials, _loggerFactory);
this._EasyShip20220323 = new EasyShip20220323Service(this.Credentials, _loggerFactory);
this._AplusContent = new AplusContentService(this.Credentials, _loggerFactory);
this._Feed = new FeedService(this.Credentials, _loggerFactory);
this._ListingsItem = new ListingsItemService(this.Credentials, _loggerFactory);
this._Restrictions = new RestrictionService(this.Credentials, _loggerFactory);
this._MerchantFulfillment = new MerchantFulfillmentService(this.Credentials, _loggerFactory);
this._Messaging = new MessagingService(this.Credentials, _loggerFactory);
this._Notification = new NotificationService(this.Credentials, _loggerFactory);
this._ProductFee = new ProductFeeService(this.Credentials, _loggerFactory);
this._ProductType = new ProductTypeService(this.Credentials, _loggerFactory);
this._Sales = new SalesService(this.Credentials, _loggerFactory);
this._Seller = new SellerService(this.Credentials, _loggerFactory);
this._Services = new ServicesService(this.Credentials, _loggerFactory);
this._ShipmentInvoicing = new ShipmentInvoicingService(this.Credentials, _loggerFactory);
this._Shipping = new ShippingService(this.Credentials, _loggerFactory);
this._ShippingV2 = new ShippingServiceV2(this.Credentials, _loggerFactory);
this._Upload = new UploadService(this.Credentials, _loggerFactory);
this._Tokens = new TokenService(this.Credentials, _loggerFactory);
this._FulFillmentInbound = new FulFillmentInboundService(this.Credentials, _loggerFactory);
this._FulFillmentInboundv20240320 = new FulFillmentInboundServicev20240320(this.Credentials, _loggerFactory);
this._FulFillmentOutbound = new FulFillmentOutboundService(this.Credentials, _loggerFactory);
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials, _loggerFactory);
this._VendorOrders = new VendorOrderService(this.Credentials, _loggerFactory);
this._VendorTransactionStatus = new VendorTransactionStatusService(this.Credentials, _loggerFactory);

AmazonCredential.DebugMode = this.Credentials.IsDebugMode;
}
Expand Down
3 changes: 3 additions & 0 deletions Source/FikaAmazonAPI/AmazonCredential.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
using FikaAmazonAPI.Utils;
using System.Collections.Generic;
using static FikaAmazonAPI.AmazonSpApiSDK.Models.Token.CacheTokenData;
using static FikaAmazonAPI.Utils.Constants;

Expand Down Expand Up @@ -57,5 +58,7 @@ public void SetAWSAuthenticationTokenData(AWSAuthenticationTokenData tokenData)
{
CacheTokenData.SetAWSAuthenticationTokenData(tokenData);
}

internal Dictionary<RateLimitType, RateLimits> UsagePlansTimings { get; set; } = RateLimitsDefinitions.RateLimitsTime();
}
}
58 changes: 0 additions & 58 deletions Source/FikaAmazonAPI/AmazonMultithreadedConnectionFactory.cs

This file was deleted.

5 changes: 2 additions & 3 deletions Source/FikaAmazonAPI/Services/AplusContentService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;

namespace FikaAmazonAPI.Services
{

public class AplusContentService : RequestService
{

public AplusContentService(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
public AplusContentService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory) : base(amazonCredential, loggerFactory)

Check warning on line 9 in Source/FikaAmazonAPI/Services/AplusContentService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{

}
Expand Down
11 changes: 4 additions & 7 deletions Source/FikaAmazonAPI/Services/AppIntegrationsV20240401.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.AppIntegrationsV20240401;
using FikaAmazonAPI.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;

namespace FikaAmazonAPI.Services
{
public class AppIntegrationsServiceV20240401: RequestService
public class AppIntegrationsServiceV20240401 : RequestService
{
public AppIntegrationsServiceV20240401(AmazonCredential amazonCredential,ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
public AppIntegrationsServiceV20240401(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory) : base(amazonCredential, loggerFactory)

Check warning on line 11 in Source/FikaAmazonAPI/Services/AppIntegrationsV20240401.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{

}
Expand Down
5 changes: 2 additions & 3 deletions Source/FikaAmazonAPI/Services/AuthorizationService.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using FikaAmazonAPI.AmazonSpApiSDK.Models.Authorization;
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
using FikaAmazonAPI.Parameter.Authorization;
using FikaAmazonAPI.Utils;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using static FikaAmazonAPI.AmazonSpApiSDK.Models.Token.CacheTokenData;

namespace FikaAmazonAPI.Services
{
public class AuthorizationService : RequestService
{
public AuthorizationService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory, IRateLimitingHandler rateLimitingHandler = null) : base(amazonCredential, loggerFactory, rateLimitingHandler)
public AuthorizationService(AmazonCredential amazonCredential, ILoggerFactory? loggerFactory) : base(amazonCredential, loggerFactory)

Check warning on line 13 in Source/FikaAmazonAPI/Services/AuthorizationService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
}
public string GetAuthorizationCode(ParameterAuthorizationCode parameterGetOrderMetrics) =>
Expand Down
Loading
Loading