UpsRestApi library for .Net used to access UPS API Catalog to browse products and view documentation.
Current version the library only support the followings feature:
- Address Validation.
- Dangerous Good.
- Chemical Reference Data.
- Acceptance Audit Pre-check.
- Pre-Notification.
- Tracking.
This library require an external API to generate UPS bearer token(Authorization (OAuth)) before use all the service. You can try to use the UpsOAuthClient to generate the token.
To install UpsOAuthClient, run:
Install-Package UpsOAuthClient -Version 1.0.3
Install-Package UpsRestApi -Version 1.0.0-beta
See NuGet docs for additonal instructions on installing via the dialog or the console.
A simple create validate addres example:
UpsOAuthClient.OAuthClient oAuthClient = new("CLIENT_ID", "CLIENT_SECRET", UpsOAuthClient.Common.Enums.ApiEnvironment.Test);
var token = Task.Run(async () => await oAuthClient.CreateToken()).GetAwaiter().GetResult();
string bearerToken = token.AccessToken;
UPSRestApi.UpsClient client = new UPSRestApi.UpsClient(bearerToken, UPSRestApi.Common.Enums.Environment.Test);
var addressResponse = client.AddressService.ValidateAddress(new UPSRestApi.Models.Common.Address(){
AddressLine = "60 Manor Station Drive",
City = "Compton",
StateProvinceCode = "CA",
PostalCode = "90221"
}).GetAwaiter().GetResult();
The test suite in this project was specifically built to produce.
-
Rename
appsettings - sample.json
toappsettings.json
-
Fill up the following configuration
- ClientID: Clinet ID provided by UPS when create your application.
- ClientSecret: Clinet Secret provided by UPS when create your application
- clientId: Clinet ID provided by UPS when create your application.
- clientSecret: Clinet Secret provided by UPS when create your application
- UPSAcount: "6 characters your ups account number,
- ShipFromAddressLine: The street number of your company address,
- ShipFromCity: The city of your company address,
- ShipFromState: The state of your company address,
- ShipFromZipcode: The postal code of your company address
NOTES: The default country of Ship from address is the United State. If you are from another country you have to change your setting on
UpsRestApi.Test.BaseTest.cs
-
Change
appsettings.json
property Copy to Output Directory toCopy always
orCopy if newer