Get U.S. & Canadian Postal Code data including city, county, state, latitude, and longitude.
Request Details
Example Request Url
https://geodata.cdxtech.com/api/geogeneral?key={key}&zipcode={zipcode}&format={format}
Description | Required | Default Value | Example | |
key | Authentication Key | key=dd76pxfi4feydh4bz_dtrjyf6flu4-987asdjhajkd555usds28ad984yhz | ||
zipcode | Zip Code Reference | zipcode=07869 | ||
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 zipcode = "07869";
string format = "json";
HttpResponseMessage message = null;
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("https://geodata.cdxtech.com");
StringBuilder url = new StringBuilder("/api/geogeneral?");
url.Append("key=").Append(key);
url.Append("&zipcode=").Append(zipCode);
url.Append("&format=").Append(format);
message = client.GetAsync(url.ToString()).Result;
}
import requests
def get_geogeneral(api_key: str, zipcode: str, response_format: str = "json"):
"""
Fetch general geo-data for a given ZIP code.
:param api_key: Your GeoData API key
:param zipcode: ZIP code to look up
:param response_format: 'json' or 'xml'
:return: Parsed JSON (if format='json') or raw text
"""
base_url = "https://geodata.cdxtech.com"
endpoint = "/api/geogeneral"
params = {
"key": api_key,
"zipcode": zipcode,
"format": response_format
}
response = requests.get(f"{base_url}{endpoint}", params=params)
response.raise_for_status() # throws an error for HTTP 4xx/5xx
if response_format.lower() == "json":
return response.json()
else:
return response.text
if __name__ == "__main__":
# Replace with your actual key
API_KEY = "your-key"
ZIP = "07869"
data = get_geogeneral(API_KEY, ZIP)
# If JSON, this will be a dict; otherwise a raw XML string
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_geogeneral(
api_key: &str,
zipcode: &str,
response_format: &str,
) -> Result> {
let base_url = "https://geodata.cdxtech.com";
let endpoint = "/api/geogeneral";
// Build the full URL with query parameters
let client = reqwest::blocking::Client::new();
let resp = client
.get(&format!("{}{}", base_url, endpoint))
.query(&[
("key", api_key),
("zipcode", zipcode),
("format", response_format),
])
.send()?
.error_for_status()?; // returns Err on 4xx/5xx
// Parse JSON; if you requested XML, you could do resp.text() instead
let json: serde_json::Value = resp.json()?;
Ok(json)
}
fn main() -> Result<(), Box> {
let api_key = "your-key";
let zipcode = "07869";
let format = "json";
match get_geogeneral(api_key, zipcode, format) {
Ok(data) => {
println!("Response JSON:\n{}", serde_json::to_string_pretty(&data)?);
}
Err(err) => {
eprintln!("Error fetching data: {}", err);
}
}
Ok(())
}
/**
* Fetch general geo-data for a given ZIP code.
*
* @param {string} apiKey Your GeoData API key
* @param {string} zipcode ZIP code to look up
* @param {string} format 'json' or 'xml'
* @returns {Promise} Parsed JSON (if format='json') or raw text
*/
async function getGeoGeneral(apiKey, zipcode, format = 'json') {
const baseUrl = 'https://geodata.cdxtech.com';
const endpoint = '/api/geogeneral';
// Build query string
const params = new URLSearchParams({ key: apiKey, zipcode, format });
// Make the request
const response = await fetch(`${baseUrl}${endpoint}?${params}`);
// Error handling
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}
// Parse or return raw text
if (format.toLowerCase() === 'json') {
return response.json();
} else {
return response.text();
}
}
// Example usage:
(async () => {
try {
const API_KEY = 'your-key';
const ZIP = '07869';
const data = await getGeoGeneral(API_KEY, ZIP);
console.log('GeoData response:', data);
} catch (err) {
console.error('Error fetching GeoData:', err);
}
})();
Dim key As String = "{your-key}"
Dim zipcode As String = "07869"
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/geogeneral?")
url.Append("key=").Append(key)
url.Append("&zipcode=").Append(zipCode)
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 zipcode As String
Dim format As String
key = "{your-key}"
zipcode = "07869"
format = "json"
Client.BaseUrl = "https://geodata.cdxtech.com/api/"
Request.Method = WebMethod.HttpGet
Request.ResponseFormat = WebFormat.Json
Request.Resource = "geogeneral?key={key}&zipcode={zipCode}&format={format}"
Request.AddUrlSegment "key", key
Request.AddUrlSegment "zipCode", zipcode
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": "GeoGeneral",
"url": "https://geodata.cdxtech.com/api/geogeneral?key={your-key}&zipcode=07869&format=json",
"status": "Success",
"tokenCharge": 1,
"message": null,
"totalResults": 1,
"results": {
"zipCode": "07869",
"city": "RANDOLPH",
"cityAliasName": "DOVER",
"elevation": "328",
"populationEstimate": "26078",
"countyName": "MORRIS",
"latitude": "40.842115",
"countyFIPS": "027",
"longitude": "-74.58229",
"stateFullName": "New Jersey",
"state": "NJ",
"areaCode": "862/973",
"stateFIPS": "34",
"timeZone": "5",
"region": "Northeast",
"dayLightSaving": "Y",
"division": "Middle Atlantic",
"landArea": "20.077",
"cbsa": "35620",
"waterArea": "0.222",
"cbsaName": "New York-Newark-Jersey City, NY-NJ-PA",
"congressionalDistrict": "07|11",
"cbsaType": "Metro",
"congressionalLandArea": "970.19|504.97",
"multiCounty": "N"
},
"usage": {
"used": 100,
"remaining": 1000
},
"duration": 0.21330259999999998,
"timeStamp": "2017-02-02T15:59:10.5668527-05:00"
}
<Root>
<Service>GeoGeneral</Service>
<Url>https://geodata.cdxtech.com/api/geogeneral?key={your-key}&zipcode=07869&format=xml</Service>
<Status>Success</Status>
<TokenCharge>1</TokenCharge>
<Message />
<TotalResults>1</TotalResults>
<Results>
<ZipCode>07869</ZipCode>
<City>RANDOLPH</City>
<CityAliasName>DOVER</CityAliasName>
<Elevation>328</Elevation>
<PopulationEstimate>26078</PopulationEstimate>
<CountyName>MORRIS</CountyName>
<Latitude>40.842115</Latitude>
<CountyFIPS>027</CountyFIPS>
<Longitude>-74.58229</Longitude>
<StateFullName>New Jersey</StateFullName>
<State>NJ</State>
<AreaCode>862/973</AreaCode>
<StateFIPS>34</StateFIPS>
<TimeZone>5</TimeZone>
<Region>Northeast</Region>
<DayLightSaving>Y</DayLightSaving>
<Division>Middle Atlantic</Division>
<LandArea>20.077</LandArea>
<CBSA>35620</CBSA>
<WaterArea>0.222</WaterArea>
<CBSAName>New York-Newark-Jersey City, NY-NJ-PA</CBSAName>
<CongressionalDistrict>07|11</CongressionalDistrict>
<CBSAType>Metro</CBSAType>
<CongressionalLandArea>970.19|504.97</CongressionalLandArea>
<MultiCounty>N</MultiCounty>
</Results>
<Usage>
<Used>100</Used>
<Remaining>1000</Remaining>
</Usage>
<Duration>0.036340399999999995</Duration>
<TimeStamp>2017-02-02T15:59:13.709104-05:00</TimeStamp>
</Root>