ShippingRates 2.1.1.234
See the version list below for details.
dotnet add package ShippingRates --version 2.1.1.234
NuGet\Install-Package ShippingRates -Version 2.1.1.234
<PackageReference Include="ShippingRates" Version="2.1.1.234" />
paket add ShippingRates --version 2.1.1.234
#r "nuget: ShippingRates, 2.1.1.234"
// Install ShippingRates as a Cake Addin #addin nuget:?package=ShippingRates&version=2.1.1.234 // Install ShippingRates as a Cake Tool #tool nuget:?package=ShippingRates&version=2.1.1.234
ShippingRates
.NET wrapper for UPS, FedEx, USPS, and DHL APIs. Use it to retrieve shipping rates from these carriers.
UPS Breaking Changes
UPS has deprecated access key authentication in favor of an OAuth 2.0 security model for all APIs. Beginning August 5, 2024, access keys will no longer be supported. More details at the UPS site: https://developer.ups.com/oauth-developer-guide?loc=en_US
The new authentication model has been implemented in the package since version 2.1.0.
How to Install
Available in the NuGet Gallery:
PM> Install-Package ShippingRates
Getting Started
// Create RateManager
var rateManager = new RateManager();
// Add desired shipping providers
// You will need an OAuth Client ID, Client Secret, and Account Number to use the UPS provider.
rateManager.AddProvider(new UPSProvider(new UPSProviderConfiguration()
{
ClientId = upsClientId,
ClientSecret = upsClientSecret,
AccountNumber = upsAccountNumber,
UseProduction = false
}));
// You will need an account # and meter # to utilize the FedEx provider.
rateManager.AddProvider(new FedExProvider(fedexKey, fedexPassword, fedexAccountNumber, fedexMeterNumber));
// You will need a userId to use the USPS provider. Your account will also need access to the production servers.
rateManager.AddProvider(new USPSProvider(uspsUserId));
// You will need a Site ID and Password to use the DHL provider.
rateManager.AddProvider(new DHLProvider(dhlSiteId, dhlPassword, useProduction: false));
// (Optional) Add RateAdjusters
rateManager.AddRateAdjuster(new PercentageRateAdjuster(.9M));
// Setup package and destination/origin addresses
var packages = new List<Package>();
packages.Add(new Package(12, 12, 12, 35, 150));
packages.Add(new Package(4, 4, 6, 15, 250));
var origin = new Address("", "", "06405", "US");
var destination = new Address("", "", "20852", "US"); // US Address
// Call GetRates()
Shipment shipment = await rateManager.GetRatesAsync(origin, destination, packages);
// Iterate through the rates returned
foreach (Rate rate in shipment.Rates)
{
Console.WriteLine(rate);
}
ShippingRates supports requesting a single rate from UPS and USPS. To do so, include the rate description as a parameter of the provider constructor.
rateManager.AddProvider(new USPSProvider(uspsUserId, "Priority Mail"));
rateManager.AddProvider(new UPSProvider(upsLicenseNumber, upsUserId, upsPassword, "UPS Ground"));
A list of valid shipping methods can be found in the documentation links below.
See the sample app in this repository for a working example.
More information can be found in Wiki.
International Rates
USPS requires a separate API call to retrieve rates for international services.
The call works the same but use the USPSInternationalProvider instead. Your current USPS credentials will work with this and will return the available services between the origin and destination addresses.
Shipping Options
Shipping options can be passed to the GetRates
function as a ShipmentOptions
object.
var shipment = await rateManager.GetRatesAsync(origin, destination, packages,
new ShipmentOptions() {
SaturdayDelivery = true,
ShippingDate = new DateTime(2020, 7, 15),
PreferredCurrencyCode = "EUR", // For FedEx only
FedExOneRate = true, // For FedEx only
FedExOneRatePackageOverride = "FEDEX_ENVELOPE" // For FedEx only
});
The following options are available:
Name | Default Value | Meaning |
---|---|---|
SaturdayDelivery | False | Enable the Saturday Delivery option for shipping rates. |
ShippingDate | null | Pickup date. The current date and time are used if not specified. |
PreferredCurrencyCode | USD | Preferred rates currency code in the ISO format. Applies to FedEx only. |
FedExOneRate | False | Use the FedEx One Rate pricing option. Applies to FedEx only. |
FedExOneRatePackageOverride | FEDEX_MEDIUM_BOX | Packing option when using FedEx OneRate. |
Saturday Delivery
If ShipmentOptions.SaturdayDelivery
is set, you can expect to receive some Saturday Delivery methods. You can check it with the Rate.Options.SaturdayDelivery
property:
var anySaturdayDeliveryMethods = shipment.Rates.Any(r => r.Options.SaturdayDelivery);
Error Handling
Normally RateManager.GetRates
wouldn't throw any exceptions. All errors are caught and reported in two properties: Errors
and InternalErrors
. Errors
are for errors coming from APIs (incorrect address etc.) It should be quite safe to show them to the end user. InternalErrors
are errors that occur during API calls processing (SOAP, HTTP requests) and errors from inside the ShippingRates. They can be used for debugging and internal reporting. Iterating through Errors and InternalErrors:
var shipment = rateManager.GetRates(origin, destination, packages);
foreach (var error in shipment.Errors)
{
Console.WriteLine(error.Number);
Console.WriteLine(error.Source);
Console.WriteLine(error.Description);
}
foreach (var error in shipment.InternalErrors)
{
Console.WriteLine(error);
}
FedEx and 556 There are no valid services available
This one can be tricky to debug. Start by setting at least $1 insurance for your shipment. For some reason, FedEx will not report errors like the wrong ZIP code for the origin address if no insurance is set.
3rd Party Docs
Developer documentation is often hard to find. The links below are provided as reference.
Credits
Originally forked from DotNetShipping by @kylewest. Package icon by Fredy Sujono.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.ServiceModel.Http (>= 4.10.3)
- System.ServiceModel.Primitives (>= 4.10.3)
- System.Text.Json (>= 6.0.9)
-
net6.0
- System.ServiceModel.Http (>= 6.0.0)
- System.ServiceModel.Primitives (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.3.291 | 653 | 9/30/2024 |
2.2.2.285 | 213 | 9/11/2024 |
2.2.1.268 | 236 | 8/16/2024 |
2.2.0.261 | 152 | 8/9/2024 |
2.1.3.253 | 313 | 7/24/2024 |
2.1.2.242 | 199 | 7/10/2024 |
2.1.1.234 | 122 | 7/5/2024 |
2.1.0 | 112 | 6/30/2024 |
2.0.218-beta | 96 | 6/4/2024 |
2.0.217-beta | 95 | 5/30/2024 |
2.0.215-beta | 1,246 | 5/10/2024 |
1.1.10.204 | 4,267 | 10/21/2023 |
1.1.9.196 | 4,401 | 12/3/2022 |
1.1.9.192 | 1,288 | 7/23/2022 |
1.1.8.187 | 493 | 7/16/2022 |
1.1.7.160 | 631 | 4/26/2022 |
1.1.6 | 3,102 | 2/23/2022 |
1.1.5.145 | 5,586 | 9/1/2021 |
1.1.4.133 | 322 | 9/1/2021 |
1.1.3.125 | 1,045 | 7/5/2021 |
1.1.2.120 | 3,937 | 4/4/2021 |
1.1.1.116 | 372 | 3/18/2021 |
1.1.0.96 | 1,688 | 11/7/2020 |
1.0.5.86 | 463 | 10/15/2020 |
1.0.4.75 | 3,066 | 9/17/2020 |
1.0.3.68 | 582 | 7/11/2020 |
1.0.2.60 | 488 | 5/5/2020 |
1.0.1.51 | 500 | 5/4/2020 |
1.0.0.43 | 435 | 4/19/2020 |
0.9.9.38-beta | 345 | 2/28/2020 |
0.9.6.16 | 497 | 2/16/2020 |