Table of Contents

UPSĀ® Integration

AddressValidation offers a complete integration to the UPSĀ® Address Validation API to provide validation for the United States and Puerto Rico.

Credentials

Before utilizing the integration, you will need a developer account along with an active UPS account. After you have signed in to the account, follow these instructions to obtain your credentials.

Installation

The easiest way to install the integration into a project is through NuGet:

dotnet package add VisusIO.AddressValidation.Integration.Ups

At application startup, you will need to register the integration with the Microsoft DI container:

builder.Services.AddUpsAddressValidation();
Important

HybridCache is required for authentication caching. Please see the Caching section for details.

Configuration

Configuration is bound from the AddressValidationSettings:Ups section.

{
  "AddressValidationSettings": {
    "Ups": {
      "AccountNumber": "<your account number>",
      "ClientId": "<your client id>",
      "ClientSecret": "<your client secret>",
      "ClientEnvironment": "PRODUCTION"
    }
  }
}
Property Required Description
AccountNumber Yes Your UPS account number
ClientId Yes OAuth 2.0 client ID issued by UPS for your registered application
ClientSecret Yes OAuth 2.0 client secret issued by UPS for your registered application
ClientEnvironment No Accepted values: PRODUCTION, DEVELOPMENT, SANDBOX. Defaults to DEVELOPMENT
EndpointUriOverride SANDBOX only Custom endpoint URI; required when ClientEnvironment is SANDBOX
Important

ClientId and ClientSecret should be stored encrypted at rest. See the Security for additional details.

Standard Example

The following example demonstrates a standard address validation request.

public class ValidateController
{
    private readonly IAddressValidationService<UpsAddressValidationRequest> _validationService;

    public ValidateController(IAddressValidationService<UpsAddressValidationRequest> validationService)
    {
        _validationService = validationService ?? throw new ArgumentNullException(nameof(validationService));
    }

    [HttpPost]
    public async Task<IActionResult> Post([FromBody] UpsAddressValidationRequest request, CancellationToken cancellationToken = default)
    {
        IAddressValidationResponse? response = await _validationService.ValidateAsync(request, cancellationToken);
        
        return response is null
            ? new NotFoundResult()
            : response.Errors.Count > 0
                ? new UnprocessableEntityObjectResult(response)
                : new OkObjectResult(response);
    }
}
Note

When ClientEnvironment is set to DEVELOPMENT only addresses in New York (NY) and California (CA) are supported.

{
  "XAVRequest": {
    "Request": {
      "RequestOption": "3"
    },
    "AddressKeyFormat": {
      "AddressLine": [
        "1 Infinite Loop"
      ],
      "PoliticalDivision2": "Cupertino",
      "PoliticalDivision1": "CA",
      "PostcodePrimaryLow": "95014",
      "CountryCode": "US"
    }
  }
}

Suggestion Example

In the event of an incomplete or ambiguous request, a potential match along with suggestions may be returned.

Note

When ClientEnvironment is set to DEVELOPMENT only addresses in New York (NY) and California (CA) are supported.

{
  "XAVRequest": {
    "Request": {
      "RequestOption": "3"
    },
    "AddressKeyFormat": {
      "AddressLine": [
        "1 Infinite Lp"
      ],
      "PoliticalDivision2": "Cupertino",
      "PoliticalDivision1": "CA",
      "PostcodePrimaryLow": "95014",
      "CountryCode": "US"
    }
  }
}
Warning

The values returned in the Suggestions collection are not guaranteed to be valid. Items within the collection should be iterated through and validated manually.

Warning

The isResidential value returned should be treated as a suggestion and not a guarantee.

Note

AddressValidation runs an internal validation engine under the covers to validate both the request and the response. You will find these results in the Warnings and Errors collections from the IAddressValidationResponse object.

Items within the Suggestion collection are not processed by the internal validator.