The Zip Code API enables you to look up detailed information for every ZIP Code in the United States. You can input ZIP Codes directly, or search for ZIP Codes using city and state parameters.
https://api.api-ninjas.com/v1/zipcode
Returns a list of ZIP Code details matching the input parameters.
At least one of the following parameters must be set:
zip
optionalThe ZIP Code to look up.
city
optionalFull name of the city to search (case-sensitive).
state
optional2-letter abbreviation of the state (case-insensitive).
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/zipcode?city=Portland&state=OR
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[
{
"zip_code": "97201",
"valid": true,
"city": "Portland",
"state": "OR",
"county": "Multnomah County",
"timezone": "America/Los_Angeles",
"area_codes": [
"503",
"971"
],
"country": "US",
"lat": "45.5074",
"lon": "-122.6898"
},
{
"zip_code": "97202",
"valid": true,
"city": "Portland",
"state": "OR",
"county": "Multnomah County",
"timezone": "America/Los_Angeles",
"area_codes": [
"971"
],
"country": "US",
"lat": "45.4803",
"lon": "-122.6451"
}
]
1
2
3
4
5
6
7
8
9
10
11
import requests
city = 'Portland'
state = 'OR'
api_url = 'https://api.api-ninjas.com/v1/zipcode?city={}&state={}'.format(city, state)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.