From 1b121cc49749c0908eab4efe0cdb18c9c2dcbb23 Mon Sep 17 00:00:00 2001 From: TManITtech Date: Thu, 19 Sep 2024 17:18:01 -0400 Subject: [PATCH 1/4] Fixed a bug when getting the next page with a list of orders that it ignored the PII setting and didn't obtain the "buyerInfo" & "shippingAddress". --- Source/FikaAmazonAPI/Services/OrderService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/FikaAmazonAPI/Services/OrderService.cs b/Source/FikaAmazonAPI/Services/OrderService.cs index 80b1be64..1349ffe2 100644 --- a/Source/FikaAmazonAPI/Services/OrderService.cs +++ b/Source/FikaAmazonAPI/Services/OrderService.cs @@ -136,11 +136,9 @@ public async Task GetOrdersAsync(ParameterOrderList searchOrderList) return orderList; } - - + public async Task GetGetOrdersByNextTokenAsync(string nextToken, ParameterOrderList searchOrderList) { - var parameterOrderList = new ParameterOrderList { MarketplaceIds = searchOrderList.MarketplaceIds, @@ -151,10 +149,13 @@ public async Task GetGetOrdersByNextTokenAsync(string nextToken, Par List> queryParameters = parameterOrderList.getParameters(); - await CreateAuthorizedRequestAsync(OrdersApiUrls.Orders, RestSharp.Method.Get, queryParameters); + await CreateAuthorizedRequestAsync(OrdersApiUrls.Orders, RestSharp.Method.Get, queryParameters, parameter: parameterOrderList); + var response = await ExecuteRequestAsync(Utils.RateLimitType.Order_GetOrders); + return response.Payload; } + public OrdersList GetOrdersList(ParameterOrderList searchOrderList) => Task.Run(() => GetOrdersListAsync(searchOrderList)).ConfigureAwait(false).GetAwaiter().GetResult(); public async Task GetOrdersListAsync(ParameterOrderList searchOrderList) From 7f89c0c586cae1da8840b17c8645d5fa53dd8824 Mon Sep 17 00:00:00 2001 From: TManITtech Date: Thu, 19 Sep 2024 17:42:01 -0400 Subject: [PATCH 2/4] Added the missing getAdditionalInputs method/call of the Amazon Shipping API v2 which needs to be called in a case where requiresAdditionalInputs = true. --- .../ShippingV2/GetAdditionalInputsRequest.cs | 49 +++++++++++++ .../ShippingV2/GetAdditionalInputsResponse.cs | 69 ++++++++++--------- .../ShippingV2/GetAdditionalInputsResult.cs | 21 +++--- Source/FikaAmazonAPI/FikaAmazonAPI.csproj | 6 +- Source/FikaAmazonAPI/Services/ApiUrls.cs | 1 + .../Services/ShippingServiceV2.cs | 11 +++ 6 files changed, 112 insertions(+), 45 deletions(-) create mode 100644 Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsRequest.cs diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsRequest.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsRequest.cs new file mode 100644 index 00000000..83cba686 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsRequest.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using System.Runtime.Serialization; +using System.Text; + +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 +{ + [DataContract] + public class GetAdditionalInputsRequest + { + /// + /// The request token returned in the response to the getRates operation. + /// + [DataMember(Name = "requestToken", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "requestToken")] + public string RequestToken { get; set; } + + /// + /// The rate identifier for the shipping offering (rate) returned in the response to the getRates operation. + /// + [DataMember(Name = "rateId", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "rateId")] + public string RateId { get; set; } + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class " + nameof(GetAdditionalInputsRequest) + " {\n"); + sb.Append($" {nameof(RequestToken)}: ").Append(RequestToken).Append("\n"); + sb.Append($" {nameof(RateId)}: ").Append(RateId).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + } + +} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResponse.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResponse.cs index 43a3641e..135557c4 100644 --- a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResponse.cs +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResponse.cs @@ -1,44 +1,47 @@ -using System; -using System.Text; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.Serialization; using Newtonsoft.Json; +using System.Runtime.Serialization; +using System.Text; -namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 { +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 +{ - /// - /// The response schema for the getAdditionalInputs operation. - /// - [DataContract] - public class GetAdditionalInputsResponse { /// - /// Gets or Sets Payload + /// The response schema for the getAdditionalInputs operation. /// - [DataMember(Name="payload", EmitDefaultValue=false)] - [JsonProperty(PropertyName = "payload")] - public GetAdditionalInputsResult Payload { get; set; } + [DataContract] + public class GetAdditionalInputsResponse + { + /// + /// Gets or Sets Payload + /// See: https://developer-docs.amazon.com/amazon-shipping/docs/shipping-api-v2-reference#getadditionalinputsresponse + /// + [DataMember(Name = "payload", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "payload", Required = Required.AllowNull, NullValueHandling = NullValueHandling.Ignore)] + public GetAdditionalInputsResult Payload { get; set; } - /// - /// Get the string presentation of the object - /// - /// String presentation of the object - public override string ToString() { - var sb = new StringBuilder(); - sb.Append("class GetAdditionalInputsResponse {\n"); - sb.Append(" Payload: ").Append(Payload).Append("\n"); - sb.Append("}\n"); - return sb.ToString(); - } + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class GetAdditionalInputsResponse {\n"); + sb.Append(" Payload: ").Append(Payload).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } - /// - /// Get the JSON string presentation of the object - /// - /// JSON string presentation of the object - public string ToJson() { - return JsonConvert.SerializeObject(this, Formatting.Indented); } } -} diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResult.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResult.cs index 464250c0..8d3bd99f 100644 --- a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResult.cs +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/GetAdditionalInputsResult.cs @@ -11,26 +11,29 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 { /// The JSON schema to use to provide additional inputs when required to purchase a shipping offering. /// [DataContract] - public class GetAdditionalInputsResult : Dictionary { + public class GetAdditionalInputsResult : Dictionary + { /// /// Get the string presentation of the object /// /// String presentation of the object - public override string ToString() { - var sb = new StringBuilder(); - sb.Append("class GetAdditionalInputsResult {\n"); - sb.Append("}\n"); - return sb.ToString(); + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class GetAdditionalInputsResult {\n"); + sb.Append("}\n"); + return sb.ToString(); } /// /// Get the JSON string presentation of the object /// /// JSON string presentation of the object - public new string ToJson() { - return JsonConvert.SerializeObject(this, Formatting.Indented); + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); } -} + } } diff --git a/Source/FikaAmazonAPI/FikaAmazonAPI.csproj b/Source/FikaAmazonAPI/FikaAmazonAPI.csproj index 83cbb008..dbd83d0c 100644 --- a/Source/FikaAmazonAPI/FikaAmazonAPI.csproj +++ b/Source/FikaAmazonAPI/FikaAmazonAPI.csproj @@ -7,9 +7,9 @@ CSharp Amazon Sp API true 8.0 - 1.7.24 - 1.7.24 - 1.7.24 + 1.7.25.1 + 1.7.25.1 + 1.7.25.1 true https://github.com/abuzuhri/Amazon-SP-API-CSharp MIT diff --git a/Source/FikaAmazonAPI/Services/ApiUrls.cs b/Source/FikaAmazonAPI/Services/ApiUrls.cs index 8e08a13a..a6203170 100644 --- a/Source/FikaAmazonAPI/Services/ApiUrls.cs +++ b/Source/FikaAmazonAPI/Services/ApiUrls.cs @@ -223,6 +223,7 @@ public static string PurchaseShipment { get => $"{_resourceBaseUrl}/shipments"; } + public static string GetAdditionalInputs(string requestToken, string rateId) => $"{_resourceBaseUrl}/shipments/additionalInputs/schema?requestToken={requestToken}&rateId={rateId}"; public static string GetTracking(string carrierId, string trackingId) => $"{_resourceBaseUrl}/tracking?carrierId={carrierId}&trackingId={trackingId}"; public static string GetShipmentDocuments(string shipmentId, string packageClientReferenceId, string format) => $"{_resourceBaseUrl}/shipments/{shipmentId}/documents?packageClientReferenceId={packageClientReferenceId}&format={format}"; public static string CancelShipment(string shipmentId) => $"{_resourceBaseUrl}/shipments/{shipmentId}/cancel"; diff --git a/Source/FikaAmazonAPI/Services/ShippingServiceV2.cs b/Source/FikaAmazonAPI/Services/ShippingServiceV2.cs index 2a8f518b..0addbd2d 100644 --- a/Source/FikaAmazonAPI/Services/ShippingServiceV2.cs +++ b/Source/FikaAmazonAPI/Services/ShippingServiceV2.cs @@ -47,6 +47,17 @@ public async Task GetRatesAsync(GetRatesRequest getRatesRequest, return null; } + public GetAdditionalInputsResult GetAdditionalInputs(GetAdditionalInputsRequest getRatesRequest) => + Task.Run(() => GetAdditionalInputsAsync(getRatesRequest)).ConfigureAwait(false).GetAwaiter().GetResult(); + public async Task GetAdditionalInputsAsync(GetAdditionalInputsRequest getRatesRequest, CancellationToken cancellationToken = default) + { + await CreateAuthorizedRequestAsync(ShippingApiV2Urls.GetAdditionalInputs(getRatesRequest.RequestToken, getRatesRequest.RateId), RestSharp.Method.Get, cancellationToken: cancellationToken); + var response = await ExecuteRequestAsync(RateLimitType.ShippingV2_GetAdditionalInputs, cancellationToken); + if (response != null && response.Payload != null) + return response.Payload; + return null; + } + public GetTrackingResult GetTracking(string carrierId, string trackingId) => Task.Run(() => GetTrackingAsync(carrierId, trackingId)).ConfigureAwait(false).GetAwaiter().GetResult(); public async Task GetTrackingAsync(string carrierId, string trackingId, CancellationToken cancellationToken = default) From 07c9ca706b44d0c205310856a72811c447f8b7c1 Mon Sep 17 00:00:00 2001 From: TManITtech Date: Thu, 19 Sep 2024 17:44:31 -0400 Subject: [PATCH 3/4] Fixed LogRequest should log to the Output Debug window when AmazonCredential.IsDebugMode = true. --- Source/FikaAmazonAPI/Services/RequestService.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/FikaAmazonAPI/Services/RequestService.cs b/Source/FikaAmazonAPI/Services/RequestService.cs index 71ceeda8..9c3e3ec9 100644 --- a/Source/FikaAmazonAPI/Services/RequestService.cs +++ b/Source/FikaAmazonAPI/Services/RequestService.cs @@ -9,6 +9,7 @@ using RestSharp.Serializers.NewtonsoftJson; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.Linq; using System.Net; @@ -179,10 +180,11 @@ private void LogRequest(RestRequest request, RestResponse response) responseUri = response.ResponseUri, errorMessage = response.ErrorMessage, }; - Console.WriteLine("\n\n"); - Console.WriteLine(string.Format("Request completed, \nRequest: {0} \n\nResponse: {1}", - JsonConvert.SerializeObject(requestToLog), - JsonConvert.SerializeObject(responseToLog))); + + Debug.WriteLine("\n\n---------------------------------------------------------\n"); + string msg = string.Format("Request completed, \nRequest: {0} \n\nResponse: {1}", requestToLog, responseToLog); + + Debug.WriteLine(msg); } } From 35855d428d7490536230b89cfd1d0fcbcc4d76fd Mon Sep 17 00:00:00 2001 From: TManITtech Date: Fri, 20 Sep 2024 10:29:06 -0400 Subject: [PATCH 4/4] Fixed "cannot convert Address to AddressInput" error in FulFillmentInboundv20240320Sample. --- .../FulFillmentInboundv20240320Sample .cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/FikaAmazonAPI.SampleCode/FulFillmentInboundv20240320Sample .cs b/Source/FikaAmazonAPI.SampleCode/FulFillmentInboundv20240320Sample .cs index b17b476e..7a66022e 100644 --- a/Source/FikaAmazonAPI.SampleCode/FulFillmentInboundv20240320Sample .cs +++ b/Source/FikaAmazonAPI.SampleCode/FulFillmentInboundv20240320Sample .cs @@ -1,4 +1,6 @@ -namespace FikaAmazonAPI.SampleCode +using FikaAmazonAPI.AmazonSpApiSDK.Models.FulfillmentInboundv20240320; + +namespace FikaAmazonAPI.SampleCode { public class FulFillmentInboundv20240320Sample { @@ -17,7 +19,7 @@ public void CreateShipmentPlan() oCreateInboundShipmentPlanRequest.DestinationMarketplaces = new List {amazonConnection.GetCurrentMarketplace.ID}; - oCreateInboundShipmentPlanRequest.SourceAddress = new FikaAmazonAPI.AmazonSpApiSDK.Models.FulfillmentInboundv20240320.Address(); + oCreateInboundShipmentPlanRequest.SourceAddress = new AddressInput(); // FikaAmazonAPI.AmazonSpApiSDK.Models.FulfillmentInboundv20240320.Address(); oCreateInboundShipmentPlanRequest.SourceAddress.AddressLine1 = "Add"; oCreateInboundShipmentPlanRequest.SourceAddress.AddressLine2 = "ADD2"; oCreateInboundShipmentPlanRequest.SourceAddress.City = "City";