FedEx® Integration
AddressValidation offers a complete integration to the FedEx® Address Validation API to provide validation for 46 countries.
Credentials
Before utilizing the integration, you will need a developer account with FedEx. 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.FedEx
At application startup, you will need to register the integration with the Microsoft DI container:
builder.Services.AddFedExAddressValidation();
Important
HybridCache is required for authentication caching. Please see the Caching section for details.
Configuration
Configuration is bound from the AddressValidationSettings:FedEx section.
{
"AddressValidationSettings": {
"FedEx": {
"AccountNumber": "<your account number>",
"ClientId": "<your client id>",
"ClientSecret": "<your client secret>",
"ClientEnvironment": "PRODUCTION"
}
}
}
| Property | Required | Description |
|---|---|---|
AccountNumber |
Yes | Your FedEx account number |
ClientId |
Yes | OAuth 2.0 client ID issued by FedEx for your registered application |
ClientSecret |
Yes | OAuth 2.0 client secret issued by FedEx for your registered application |
ClientEnvironment |
No | Accepted values: PRODUCTION, DEVELOPMENT, SANDBOX. Defaults to DEVELOPMENT |
Locale |
No | IETF BCP 47 language tag for the response locale (e.g., en-US). When omitted, FedEx uses its default locale. |
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<FedExAddressValidationRequest> _validationService;
public ValidateController(IAddressValidationService<FedExAddressValidationRequest> validationService)
{
_validationService = validationService ?? throw new ArgumentNullException(nameof(validationService));
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] FedExAddressValidationRequest 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);
}
}
{
"addressesToValidate": [
{
"address": {
"streetLines": [
"1000 5th Ave"
],
"city": "New York",
"stateOrProvince": "NY",
"postalCode": "10028",
"countryCode": "US"
}
}
]
}
Note
transactionId will always be present in customResponseData. When CustomerTransactionId is set on the request, customerTransactionId will also be present with the same value echoed back by the FedEx API.
Note
The Suggestions collection will always be empty as the FedEx® Address Validation API does not provide address suggestions.
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.