Developer forum

Forum » Ecommerce - Standard features » UPS OAuth exception with RatedShipmentAlert

UPS OAuth exception with RatedShipmentAlert

Mario Santos Dynamicweb Employee
Mario Santos
Reply

Hi,

We are using the new UPS OAuth API credentials and we ran into an issue that results in an exception:

2024-06-10 21:23:12.9114|INFO|eCom/ShippingProvider/Dynamicweb.Ecommerce.ShippingProviders.UPS.UPS/Request|'Newtonsoft.Json.Linq.JProperty' does not contain a definition for 'Code'

2024-06-10 21:23:12.8964|INFO|eCom/ShippingProvider/Dynamicweb.Ecommerce.ShippingProviders.UPS.UPS/Response|UCART1555: {"RateResponse":{"Response":{"ResponseStatus":{"Code":"1", "Description":"Success"}, "Alert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "TransactionReference":{"CustomerContext":"uat-ic.mydwsite1.com:443", "TransactionIdentifier":"ciewssoas6b8y8bHZkhZNy"}}, "RatedShipment":{"Service":{"Code":"01", "Description":""}, "RatedShipmentAlert":{"Code":"110971", "Description":"Your invoice may vary from the displayed reference rates"}, "BillingWeight":{"UnitOfMeasurement":{"Code":"LBS", "Description":"Pounds"}, "Weight":"22.0"}, "TransportationCharges":{"CurrencyCode":"USD", "MonetaryValue":"248.55"}, "ServiceOptionsCharges":{"CurrencyCode":"USD", "MonetaryValue":"0.00"}, "TotalCharges":{"CurrencyCode":"USD", "MonetaryValue":"248.55"}, "GuaranteedDelivery":{"BusinessDaysInTransit":"1", "DeliveryByTime":"10:30 A.M."}, "RatedPackage":{"TransportationCharges":{"CurrencyCode":"USD", "MonetaryValue":"248.55"}, "ServiceOptionsCharges":{"CurrencyCode":"USD", "MonetaryValue":"0.00"}, "TotalCharges":{"CurrencyCode":"USD", "MonetaryValue":"248.55"}, "Weight":"21.5", "BillingWeight":{"UnitOfMeasurement":{"Code":"LBS", "Description":"Pounds"}, "Weight":"22.0"}}}}}

 

After debugging it, I found that it is related to RatedShipmentAlert object, which sometimes returns an array and others just an object.

https://dev.azure.com/dynamicwebsoftware/_git/Dynamicweb?path=/src/22%20-%20Providers/Ecommerce/Shipping/Dynamicweb.Ecommerce.ShippingProviders.UPS/UPS.cs - lines 758-770

A possible fix could be:

var ratedShipmentAlert = responseObj?.RateResponse?.RatedShipment?.RatedShipmentAlert;
                                        if (ratedShipmentAlert != null)
                                        {
                                            if (ratedShipmentAlert.Type == Newtonsoft.Json.Linq.JTokenType.Array)
                                            {
                                                foreach (var alert in ratedShipmentAlert)
                                                {
                                                    string code = alert?.Code?.ToString();
                                                    string description = alert?.Description?.ToString();
                                                    if (!string.IsNullOrEmpty(code) || !string.IsNullOrEmpty(description))
                                                    {
                                                        order.ShippingProviderWarnings.Add($"Code: {code}, Description: {description}");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                string code = ratedShipmentAlert?.Code?.ToString();
                                                string description = ratedShipmentAlert?.Description?.ToString();
                                                if (!string.IsNullOrEmpty(code) || !string.IsNullOrEmpty(description))
                                                {
                                                    order.ShippingProviderWarnings.Add($"Code: {code}, Description: {description}");
                                                }
                                            }
                                        }

 

 

 

DW 9.17.5.
BR Mario


Replies

 
Rasmus Sanggaard Dynamicweb Employee
Rasmus Sanggaard
Reply
This post has been marked as an answer

Hi Mario,

Thnx for the detailed description. I have added it to the bug queue. #20058 if you want to track it. 

 

BR Rasmus Sanggaard

Votes for this answer: 1

 

You must be logged in to post in the forum