I'll go ahead and post @Matt's answer, since I've used the SmartyStreets ZIP Code API for just that purpose. You can query this API one of three ways:
- ZIP Code
- City + State
- City + State + ZIP Code
For a single ZIP Code (which is what you are asking about) this is a simple GET
request:
curl -v 'https://us-zipcode.api.smartystreets.com/lookup?
auth-id=YOUR+AUTH-ID+HERE&
auth-token=YOUR+AUTH-TOKEN+HERE&
zipcode=65202'
The response (with valid AUTH-ID
and AUTH-TOKEN
) is:
[
{
"input_index": 0,
"city_states": [
{
"city": "Columbia",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": true
},
{
"city": "Hinton",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Lindbergh",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Midway",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Murry",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Prathersville",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Shaw",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
},
{
"city": "Stephens",
"state_abbreviation": "MO",
"state": "Missouri",
"mailable_city": false
}
],
"zipcodes": [
{
"zipcode": "65202",
"zipcode_type": "S",
"default_city": "Columbia",
"county_fips": "29019",
"county_name": "Boone",
"state_abbreviation": "MO",
"state": "Missouri",
"latitude": 38.99775,
"longitude": -92.30798,
"precision": "Zip5",
"alternate_counties": [
{
"county_fips": "29027",
"county_name": "Callaway",
"state_abbreviation": "MO",
"state": "Missouri"
}
]
}
]
}
]
As you can see, this gives the same list of cities as your picture example. It also includes more detailed information on the first city_state
in the list.
For completeness, here is a sample request demonstrating all three query options. (n.b. For any request outside of a single ZIP Code, the API requires a POST
call):
curl -v 'https://us-zipcode.api.smartystreets.com/lookup?
auth-id=YOUR+AUTH-ID+HERE&
auth-token=YOUR+AUTH-TOKEN+HERE'
-H "Content-Type: application/json"
--data-binary '
[
{
"zipcode":"12345"
},
{
"city":"North Pole",
"state":"AK"
},
{
"city":"cupertino",
"state":"CA",
"zipcode":"95014"
}
]'
And here is the response for that example request:
[
{
"input_index": 0,
"city_states": [
{
"city": "Schenectady",
"state_abbreviation": "NY",
"state": "New York",
"mailable_city": true
},
{
"city": "General Electric",
"state_abbreviation": "NY",
"state": "New York",
"mailable_city": false
},
{
"city": "Schdy",
"state_abbreviation": "NY",
"state": "New York",
"mailable_city": false
}
],
"zipcodes": [
{
"zipcode": "12345",
"zipcode_type": "U",
"default_city": "Schenectady",
"county_fips": "36093",
"county_name": "Schenectady",
"state_abbreviation": "NY",
"state": "New York",
"latitude": 42.81565,
"longitude": -73.94232,
"precision": "Zip5"
}
]
},
{
"input_index": 1,
"city_states": [
{
"city": "North Pole",
"state_abbreviation": "AK",
"state": "Alaska",
"mailable_city": true
}
],
"zipcodes": [
{
"zipcode": "99705",
"zipcode_type": "S",
"default_city": "North Pole",
"county_fips": "02090",
"county_name": "Fairbanks North Star",
"state_abbreviation": "AK",
"state": "Alaska",
"latitude": 64.77911,
"longitude": -147.36885,
"precision": "Zip5"
}
]
},
{
"input_index": 2,
"city_states": [
{
"city": "Cupertino",
"state_abbreviation": "CA",
"state": "California",
"mailable_city": true
}
],
"zipcodes": [
{
"zipcode": "95014",
"zipcode_type": "S",
"default_city": "Cupertino",
"county_fips": "06085",
"county_name": "Santa Clara",
"state_abbreviation": "CA",
"state": "California",
"latitude": 37.32056,
"longitude": -122.03865,
"precision": "Zip5"
}
]
}
]
I hope that helps!
EDIT - I've updated this with an example specific to the question. Thanks to @AmyAnuszewski for calling that out.