Address Validation¶
How Address Validation Works¶
- All address validation is processed through the United States Post Office. UPS and FedEx both use the USPS as their backend to deliver address validation results. This means that all three carrires are going to provide almost identical results.
The USPS is the canonical source of truth for U. S. addresses.
From the UPS docs:
UPS Address Validation uses U.S. Postal Service guidelines to thoroughly check the city, state and postal code of every shipment. UPS provides up to ten alternate addresses, including an accuracy rate that lets your customers know how closely the address they entered matches the suggested address.
- Address Validation provided by UPS, FedEx, and USPS does NOT indicate a given address is valid or not! It will only return alternative addresses and an accuracy rate. It is best to think of it as an address suggestion API.
- Address validation is only available in the U.S.
UPS¶
Note
UPS restricts Street Level Address Validation to only California (CA) and New York (NY) addresses in their test environment. See: debugMode in Shipment Parameters.
Example¶
Here is an example address validation using UPS:
<?php
$av = new \RocketShipIt\AddressValidate('UPS');
$av->setParameter('toState', 'CA');
$av->setParameter('toCity', 'San Diego');
$av->setParameter('toAddr1', '2920 Zoo Drive');
$av->setParameter('toCode', '92112');
$av->setParameter('toCountry', 'US');
$response = $av->validateStreetLevel();
Parameters¶
Here are all of the availble parameters you can set for an address validation:
<?php
$av->setParameter('toName', 'John Smith');
$av->setParameter('toState', 'CA');
$av->setParameter('toCity', 'San Diego');
$av->setParameter('toAddr1', '2920 Zoo Drive');
$av->setParameter('toAddr2', 'Building A');
$av->setParameter('toCode', '92112');
$av->setParameter('toExtendedCode', '0551');
$av->setParameter('toCountry', 'US');
FedEx¶
Note
Unfortunately, FedEx does not allow address validation in their testing environment. Make sure you are in production mode to test address validation.
Example:
<?php
$av = new \RocketShipIt\AddressValidate('FedEx');
$av->setParameter('toAddr1', '76 Sycamore St');
$av->setParameter('toAddr2', 'Apt 2');
$av->setParameter('toCity', 'San Francisco');
$av->setParameter('toState', 'CA');
$av->setParameter('toCode', '94110');
$response = $av->validate();
USPS¶
Example address validation:
<?php
$av = new \RocketShipIt\AddressValidate('STAMPS');
$av->setParameter('toState', 'CA');
$av->setParameter('toCity', 'San Diego');
$av->setParameter('toAddr1', '2920 Zoo Drive');
$av->setParameter('toCode', '92112');
$response = $av->validate();
Example using the USPS API instead of Stamps.com:
<?php
$av = new \RocketShipIt\AddressValidate('USPS');
$av->setParameter('toAddr1', '6406 Ivy Lane');
$av->setParameter('toAddr2', 'apt 103');
$av->setParameter('toCity', 'Greenbelt');
$av->setParameter('toState', 'MD');
$response = $av->validate();
Look up city and state from zipcode:
<?php
$av = new \RocketShipIt\AddressValidate('USPS');
$av->setParameter('toCode', '94115');
$response = $av->lookupCityState();
Determine if an Address is Residential¶
UPS:
<?php
$av = new \RocketShipIt\AddressValidate('UPS');
$av->setParameter('toName', 'Tommy Test');
$av->setParameter('toState', 'CA');
$av->setParameter('toAddr1', '4092 N. Chestnut Diagonal');
$av->setParameter('toCity', 'Fresno');
$av->setParameter('toCode', '93726');
$response = $av->validateStreetLevel();
if ($response['Data']['Residential']) {
echo 'This address is residential';
} else {
echo 'This address is a commercial address';
}
FedEx:
<?php
$av = new \RocketShipIt\AddressValidate('fedex');
$av->setParameter('toAddr1', '4092 N. Chestnut Diagonal');
$av->setParameter('toCity', 'Fresno');
$av->setParameter('toState', 'CA');
$av->setParameter('toCode', '93726');
$response = $av->validate();
var_dump($response['Data']['Residential']);