A Codeigniter library which integrates with the USPS shipping and address verification APIs
- Unpack the contents into your system folder.
- Edit the /application/config/usps.php and change the "user_id" to the user id supplied by USPS when you registered for your WebTools account.
Note: The USPS test API is enabled by default. Set "test" to FALSE to enable the USPS production API
$this->load->library('USPS');
//CREATE AN ARRAY OF ADDRESSES (MAX 5)
$addresses = array(
'0' => array(
'firm_name' => 'XYZ Company',
'address1' => '1234 Fake St.',
'address2' => 'Apt #1234',
'city' => 'Testingville',
'state' => 'AZ',
'zip5' => '12345',
'zip4' => '1234'
),
'1' => array(
'firm_name' => 'ABC Company',
'address1' => '1234 Real St.',
'address2' => 'Suite #1234',
'city' => 'Realville',
'state' => 'AZ',
'zip5' => '54321',
'zip4' => '4321'
)
);
//RUN ADDRESS STANDARDIZATION REQUEST
$verified_address = $this->usps->address_standardization($addresses);
//OUTPUT RESULTS
print_r($verified_address);
$this->load->library('USPS');
//CREATE AN ARRAY OF ADDRESSES (MAX 5)
$addresses = array(
'0' => array(
'firm_name' => 'XYZ Company',
'address1' => '1234 Fake St.',
'address2' => 'Apt #1234',
'city' => 'Testingville',
'state' => 'AZ'
),
'1' => array(
'firm_name' => 'ABC Company',
'address1' => '1234 Real St.',
'address2' => 'Suite #1234',
'city' => 'Realville',
'state' => 'AZ'
)
);
//RUN ZIP CODE LOOKUP
$zip_code_lookup = $this->usps->zipcode_lookup($addresses);
//OUTPUT RESULTS
print_r($zip_code_lookup);
$this->load->library('USPS');
//CREATE AN ARRAY OF ZIPCODES (MAX 5)
$addresses = array(
'0' => array(
'zip5' => '12345',
),
'1' => array(
'zip5' => '54321',
)
);
//RUN CITY/STATE LOOKUP
$city_state_lookup = $this->usps->city_state_lookup($addresses);
//OUTPUT RESULTS
print_r($city_state_lookup);
Licensed under the Open Software License 3.0. View OSL-3.0 license.
- View the USPS API Documentation
- View more about the SimpleXML return type.