/UPSRestApi

Ups Rest Api Client library for .Net

Primary LanguageC#MIT LicenseMIT

UPSRestApi

Overview

UpsRestApi library for .Net used to access UPS API Catalog to browse products and view documentation.

Features

Current version the library only support the followings feature:

  1. Address Validation.
  2. Dangerous Good.
    • Chemical Reference Data.
    • Acceptance Audit Pre-check.
    • Pre-Notification.
  3. Tracking.

Dependencies

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

Installation

Install-Package UpsRestApi -Version 1.0.0-beta

See NuGet docs for additonal instructions on installing via the dialog or the console.

Usage

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();

Testing

The test suite in this project was specifically built to produce.

Settings

  1. Rename appsettings - sample.json to appsettings.json

  2. 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

  3. Change appsettings.json property Copy to Output Directory to Copy always or Copy if newer