List all U.S. ZIP Codes associated with any city/state combination.
Request Details
Example Request Url
https://geodata.cdxtech.com/api/geofindzip?key={key}&state={state}&county={county}&city={city}&format={format}
Description | Required | Default Value | Example | |
key | Authentication Key | key=dd76pxfi4feydh4bz_dtrjyf6flu4-987asdjhajkd555usds28ad984yhz | ||
state | State Reference | state=nj | ||
city | City Reference | city=morristown | ||
format | Output Formatting | json | format=json (supported formats: json, xml, csv) |
Coding Examples
Here are some coding examples to get you started. Please feel free to contact support if you need additional assistance.
string key = "{your-key}";
string state = "nj";
string city = "morristown";
string format = "json";
HttpResponseMessage message = null;
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("https://geodata.cdxtech.com");
StringBuilder url = new StringBuilder("/api/geofindzip?");
url.Append("key=").Append(key);
url.Append("&state=").Append(state);
url.Append("&city=").Append(city);
url.Append("&format=").Append(format);
message = client.GetAsync(url.ToString()).Result;
}
import requests
def get_geofindzip(api_key, state, city, response_format="json"):
"""Fetch ZIP codes for a given state and city using the API."""
base_url = "https://geodata.cdxtech.com"
endpoint = "/api/geofindzip"
url = f"{base_url}{endpoint}"
params = {
"key": api_key,
"state": state,
"city": city,
"format": response_format,
}
response = requests.get(url, params=params)
response.raise_for_status()
try:
return response.json()
except ValueError:
return response.text
if __name__ == "__main__":
key = "{your-key}"
state = "nj"
city = "morristown"
format = "json"
data = get_geofindzip(key, state, city, format)
import json
if isinstance(data, (dict, list)):
print(json.dumps(data, indent=2))
else:
print(data)
// Cargo.toml
// [dependencies]
// reqwest = { version = "0.11", features = ["blocking", "json"] }
// serde = { version = "1.0", features = ["derive"] }
// serde_json = "1.0"
use std::error::Error;
fn get_geofindzip(
api_key: &str,
state: &str,
city: &str,
response_format: &str,
) -> Result> {
let client = reqwest::blocking::Client::new();
let resp = client
.get("https://geodata.cdxtech.com/api/geofindzip")
.query(&[
("key", api_key),
("state", state),
("city", city),
("format", response_format),
])
.send()?
.error_for_status()?;
let json: serde_json::Value = resp.json()?;
Ok(json)
}
fn main() -> Result<(), Box> {
let api_key = "{your-key}";
let state = "nj";
let city = "morristown";
let format = "json";
match get_geofindzip(api_key, state, city, format) {
Ok(data) => println!("Response JSON:\n{}", serde_json::to_string_pretty(&data)?),
Err(err) => eprintln!("Error fetching data: {}", err),
}
Ok(())
}
async function getGeofindZip({ key, state, city, format = "json" }) {
const baseUrl = "https://geodata.cdxtech.com";
const endpoint = "/api/geofindzip";
const params = new URLSearchParams({ key, state, city, format });
const url = `${baseUrl}${endpoint}?${params.toString()}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const text = await response.text();
try {
return JSON.parse(text);
} catch {
return text;
}
}
// Example usage:
(async () => {
const key = "{your-key}";
const state = "nj";
const city = "morristown";
const format = "json";
try {
const data = await getGeofindZip({ key, state, city, format });
console.log("Response:", data);
} catch (err) {
console.error("Error fetching data:", err);
}
})();
Dim key As String = "{your-key}"
Dim state As String = "nj"
Dim city As String = "morristown"
Dim format As String = "json"
Dim message As HttpResponseMessage = Nothing
Using client As New HttpClient()
client.BaseAddress = New Uri("https://geodata.cdxtech.com")
Dim url As New StringBuilder("/api/geofindzip?")
url.Append("key=").Append(key)
url.Append("&state=").Append(state)
url.Append("&city=").Append(city)
url.Append("&format=").Append(format)
message = client.GetAsync(url.ToString()).Result
End Using
The following is for the VBA-WEB Excel template available at http://vba-tools.github.io/VBA-Web/
Dim Client As New WebClient
Dim Request As New WebRequest
Dim key As String
Dim state As String
Dim city AS String
Dim format As String
key = "{your-key}"
state = "nj"
city = "morristown"
format = "json"
Client.BaseUrl = "https://geodata.cdxtech.com/api/"
Request.Method = WebMethod.HttpGet
Request.ResponseFormat = WebFormat.Json
Request.Resource = "geofindzip?key={key}&state={state}&city={city}&format={format}"
Request.AddUrlSegment "key", key
Request.AddUrlSegment "state", state
Request.AddUrlSegment "city", city
Request.AddUrlSegment "format", format
Set Response = Client.Execute(Request)
Output Examples
Here are some output data examples. You can also use the Report Generator tab to export specific data files.
{
"service": "GeoFindZip",
"url": "https://geodata.cdxtech.com/api/geofindzip?key={your-key}&state=nj&city=morristown&format=json",
"status": "Success",
"tokenCharge": 1,
"message": null,
"totalResults": 3,
"results": [{
"zipCode": "07960"
},
{
"zipCode": "07962"
},
{
"zipCode": "07963"
}],
"usage": {
"used": 100,
"remaining": 1000
},
"duration": 0.0594392,
"timeStamp": "2017-02-02T15:06:31.7915949-05:00"
}
<Root>
<Service>GeoFindZip</Service>
<Url>https://geodata.cdxtech.com/api/geofindzip?key={your-key}&state=nj&city=morristown&format=xml</Url>
<Status>Success</Status>
<TokenCharge>1</TokenCharge>
<Message />
<TotalResults>3</TotalResults>
<Results>
<ZipCode>07960</ZipCode>
</Results>
<Results>
<ZipCode>07962</ZipCode>
</Results>
<Results>
<ZipCode>07963</ZipCode>
</Results>
<Usage>
<Used>100</Used>
<Remaining>1000</Remaining>
</Usage>
<Duration>0.058671799999999996</Duration>
<TimeStamp>2017-02-02T15:06:34.3861301-05:00</TimeStamp>
</Root>