18

I need an API to give me the zip code of a location when someone enters a location like Los Angeles, California. I have seen many APIs that give you the details by the zip code, but I need the reverse.

Anonymous
  • 351
  • 1
  • 5
  • 16

4 Answers4

23

Check out the API from SmartyStreets.

As with the USPS address information API (mentioned above), you provide an address, the API provides the verified, standardized address along with the complete ZIP Code (5-digit code, Plus 4 Code, and Delivery Point).

Feel free to experiment with the free demo.

The advantages of this API over the USPS API are numerous. Also, the USPS API is meant specifically "to facilitate USPS shipping transactions only". SmartyStreets utilizes official, current USPS data.

**UPDATE: New users can sign up for a free trial.

***UPDATE: SmartyStreets now offers an address API and a ZIP Code API.

In the interest of full disclosure, I'm a software developer at SmartyStreets.

Michael Whatcott
  • 5,603
  • 6
  • 36
  • 50
  • 3
    Why is there a link "DO NOT READ THIS" on the site? I don't want to be weak but the curiosity is killing me ... why would you put a link like that on the site ... probably because you WANT me to "read this" right? But ... it says NOT TO!! (fetal position) :D – Gary O. Stenstrom Feb 02 '16 at 15:50
  • 5
    Our plan is working perfectly... – Michael Whatcott Feb 02 '16 at 19:37
11

USPS has an address information api. You give it an address and it gives you the zip code. And as the commenters said, you need to provide an address, because many cities have multiple zip codes.

Jon7
  • 7,165
  • 2
  • 33
  • 39
  • 9
    Excellent point about the multiple zip codes. But the USPS' API can only be used if you're mailing things with the information you request... – Matt Jun 21 '12 at 14:50
  • 2
    There's also the undocumented JSON API that their [online ZIP code lookup tool](https://tools.usps.com/zip-code-lookup.htm?byaddress) uses, which doesn't require any tokens or registration, just a user agent string: `curl 'https://tools.usps.com/tools/app/ziplookup/zipByAddress' --data 'companyName=&address1=1234 example rd&address2=&city=Anytown&state=NY&urbanCode=&zip=12345' -H "User-Agent: Mozilla/5.0"` They'll probably get mad if you start using it heavily though. – Skylar Ittner Feb 26 '20 at 01:15
  • You can use https://thezipcodes.com as well. – nkkumawat Dec 31 '20 at 13:00
8

This Zip Code API provides the following functions:

  • Distance Between Zip Code API
  • Zip Codes in Radius API
  • Zip Code to City and State API and Zip Code to Latitude/Longitude API
  • Zipcode based on City and State
Bob Bickel
  • 349
  • 2
  • 3
  • This is a good one! Thanks – Joel Mar 31 '16 at 19:43
  • I can't find the Zip Codes in Radius API information. That's exactly what I need. Hopefully you can point me in the right direction? – Casey Crookston Dec 30 '16 at 19:32
  • For example it cant find zip for Sterling Heights, MI – fdrv Feb 07 '18 at 09:12
  • It has the reverse way - zipcode to Sterling Heights - http://www.zipcodeapi.com/API#zipToLoc - 48310. Just a bad search capability for matching a two word city name... – Bob Bickel Feb 08 '18 at 13:14
  • I sent an email to the developer and they fixed it. They said they had converted the "St" into "Saint" so the search they were running was "Sainterling Heights"... – Bob Bickel Feb 08 '18 at 14:38
1

They have a cross reference database of zipcode, to lat/long-itude, and the weather station.

I am not aware of anything freely available, you will likely need to pay to compile this