Jonas Stawski

Everything .NET and More

Cleaning Up Your US Addresses in your Database

I was in need of querying some sort of database or web service to clean up a user entered address. I was going to go the route of screen scraping, but after doing some research I read in the USPS Web Site about their Web Tools and their Address Information APIs (AIA). Under the AIA you have 3 tools: Address Standardization, Zip Code Lookup, and City/State Lookup. I was in need of Address Standardization, so I started reading. Their process and documentation did not seem so straightforward so here is a more simplified help on how to do it.

Step 1

Register for their service. You will get an email with a username and password. Everywhere in their documentation they mention UserID and they are referring to the username you received in the email.

Step 2

Read the documentation. The Development Guide did not get me much. Since I was interested in Address Verification I read the Address Verification.

Step 3

The way their API works is you generate an HTTP request with 2 parameters to the address specified in the email. The 2 parameters are the application you want to query and an XML containing your UserID (username) and the address you want to verify. Please read the documentation for more details on the schema of the XML. It is very simple! The response of this request will contain another XML specifying the result, whether there was an error or the correct address.

Step 4

Test the API and make sure it works.

Step 5

Call the Customer Service phone specified in the docs (or the website) and ask them to switch your UserID (username) to production. They will send you another email and all you have to do is change the URL to the production one.

In another post I will show code on how to create the request and response to verify the address. I might even feel generous and provide some code to call the service through AJAX with JavaScript.

Happy Address Verification!

Add comment