Skip to main content

POST /api/city

Find postal codes for a given city name. For US queries, a state is required. For other countries, state/region filtering is optional.

Request

POST https://postaldatapi.com/api/city
Content-Type: application/json

Body Parameters

ParameterTypeRequiredDescription
citystringYesCity name to search for
statestringUS onlyFull state name (e.g., "California")
STstringUS onlyTwo-letter state abbreviation (e.g., "CA")
apiKeystringYesYour API key
countrystringNoISO 3166-1 alpha-2 country code (default: "US")
note

For US queries, either state or ST must be provided. For non-US queries, both are optional.

Response

Success (200)

{
"zipcodes": ["90209", "90210", "90211", "90212", "90213"],
"performance": { "totalTime": "3ms" },
"balance": 4.99
}

Fuzzy match (200)

If no exact match is found but a close match exists, the response includes the matched city/state:

{
"zipcodes": ["90209", "90210", "90211"],
"matchedCity": "Beverly Hills",
"matchedState": "California",
"matchedST": "CA",
"performance": { "totalTime": "4ms" },
"balance": 4.99
}

Response Fields

FieldTypeDescription
zipcodesstring[]List of postal codes matching the city
matchedCitystring(optional) Actual city name if fuzzy-matched
matchedStatestring(optional) Actual state name if fuzzy-matched
matchedSTstring(optional) State abbreviation if fuzzy-matched
performanceobjectTiming breakdown
balancenumberAccount balance after this query (USD)

Examples

# US city search (state required)
curl -X POST https://postaldatapi.com/api/city \
-H "Content-Type: application/json" \
-d '{"city": "Beverly Hills", "ST": "CA", "apiKey": "YOUR_API_KEY"}'

# German city search (no state required)
curl -X POST https://postaldatapi.com/api/city \
-H "Content-Type: application/json" \
-d '{"city": "Berlin", "country": "DE", "apiKey": "YOUR_API_KEY"}'

Errors

StatusErrorCause
400Missing required field: cityNo city in request body
400Missing 'state' or 'ST' in request bodyUS query without state
401Invalid API keyAPI key does not exist or was revoked
402Insufficient balanceAccount balance is zero
404No ZIP codes found for the given city/stateNo matching postal codes
429Rate limit exceededToo many requests

SDK Examples

from postaldatapi import PostalDataPI

client = PostalDataPI(api_key="YOUR_API_KEY")

# US city search
result = client.search_city("Beverly Hills", state="CA")
print(result.postal_codes) # ['90209', '90210', '90211', ...]

# German city search
de = client.search_city("Berlin", country="DE")
print(len(de.postal_codes)) # many Berlin postal codes