get 9 digit zip code from 5 digit zip code, programmatic, api

CQM picture CQM · Feb 22, 2013 · Viewed 17.4k times · Source

I have 5 digit zip codes, these are retrieved from Google Maps Api.

My dilemma is that I have to connect to a remote database which also contains addresses. If the address does not exist in that database, I have to write it, if it does exist then I do nothing except store the ID that database has assigned to the address. The problem arises since the api to check this database does not take wildcards, the addresses in that database have 9 digit zip codes (5+4) and will not return that the rest of the address matches my address with 5 digit zip codes.

The remote system will tell me that the address does not exist with the ones I send it.

So to prevent duplicate addresses from being written to the database I would need to find the 9 digit version of the zip code I have before sending it.

How would this be done? Is there a formula for determining what the last 4 digits of a 5 digit address are? Does the USPS have an API? Does the Census have a giant table?

Insight appreciated

Answer

Matt picture Matt · Feb 22, 2013

You are only allowed to use the USPS API for information if you are using the USPS to send out mail...

But you could check out SmartyStreets (I used to work there) or another CASS-Certified vendor. They are licensed for address verification, and you can also perform city-state and ZIP code lookups without an address (depending on who you choose).

I think you'll find them much easier and more comprehensive than the default USPS web service.

Here's some sample code... take your pick: https://github.com/smartystreets/LiveAddressSamples