The GetZipCodesForCityAndState method returns all possible ZIP Codes for a given city/state combination.
Endpoint
GET:https://pav3.esendex.us/PavService.svc/GetZipCodesForCityAndState?City={CITY}&State={STATE}&LicenseKey={LICENSEKEY}
Syntax
GetZipCodesForCityAndState(City, State, LicenseKey)
Request Parameters
| Parameter Name | Description | Data Type | Required | Sample Value | 
|---|---|---|---|---|
| City | City name. | String | True | Chesapeake | 
| State | Two-letter state name abbreviation. | String | True | VA | 
| LicenseKey | Your license key. | String | True | 00000000-0000-0000-0000-000000000000 | 
Response
Returns: ZipCodesResponse object
Code Samples
You can use any programming language you want with our API, as long as it can make a REST or SOAP call. Here are examples for some of the most common platforms.
C#
// https://pav3.esendex.us/PavService.svc?wsdl was added as a Service Reference and given the name WSDL
using System;
using WSDL;
var config = PavServiceClient.EndpointConfiguration.pavws_secure;
var client = new PavServiceClient(config);
var city = "Chesapeake";
var state = "VA";
var licenseKey = "YOUR_LICENSE_KEY";
var response = await client.GetZipCodesForCityAndStateAsync(city, state, licenseKey);
var returnCodeDescription = response.ReturnCode switch
{
    0 => "Success",
    1 => "Invalid input",
    2 => "Invalid license key",
    3 => "Returned 0 ZIP Codes (no matches)",
    4 => "Outside of latitude/longitude range",
    _ => "Unknown return code"
};
Console.WriteLine($"Return Code: {response.ReturnCode} - {returnCodeDescription}");
if (response.ZipCodes is not null)
{
    foreach (var zip in response.ZipCodes)
    {
        Console.WriteLine($"ZIP Code: {zip}");
    }
}
Console.ReadLine();
JavaScript
const params = new URLSearchParams({
    'City': 'Chesapeake',
    'State': 'VA',
    'LicenseKey': '00000000-0000-0000-0000-000000000000'
});
const url = 'https://pav3.esendex.us/PavService.svc/GetZipCodesForCityAndState?' + params.toString();
const options = {
    headers: {
        'Accept': 'application/json'
    }
};
const response = await fetch(url, options);
const json = await response.json();
console.log(json);
JSON Response
{
  "ReturnCode": 0,
  "ZipCodes": [
    "23320",
    "23321",
    "23322",
    "23323",
    "23324",
    "23325",
    "23326",
    "23327",
    "23328"
  ]
}
PHP with cURL
<?php
$client = new SoapClient('https://pav3.esendex.us/PavService.svc?wsdl');
$param = array(
  'City' => 'Chesapeake'
  , 'State' => 'VA'
  , 'LicenseKey' => 'YOUR LICENSE KEY'
);
$result = $client->GetZipCodesForCityAndState($param);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
Python
import httpx
headers = {"Accept": "application/json"}
url = "https://pav3.esendex.us/PavService.svc/GetZipCodesForCityAndState"
request = {
    "City": "Chesapeake",
    "State": "VA",
    "LicenseKey": "00000000-0000-0000-0000-000000000000",
}
with httpx.Client(headers=headers) as client:
    response = client.get(url=url, params=request)
response.raise_for_status()
print(response.json())
Ruby
require 'json'
require 'net/http'
headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://pav3.esendex.us/PavService.svc/GetZipCodesForCityAndState')
params = {
  'City': 'Chesapeake',
  'State': 'VA',
  'LicenseKey': '00000000-0000-0000-0000-000000000000'
}
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
puts JSON.parse(response)
XML Response
<ZipCodesResponse xmlns="pav3.esendex.us" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <ReturnCode>0</ReturnCode>
  <ZipCodes xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <a:string>23320</a:string>
    <a:string>23321</a:string>
    <a:string>23322</a:string>
    <a:string>23323</a:string>
    <a:string>23324</a:string>
    <a:string>23325</a:string>
    <a:string>23326</a:string>
    <a:string>23327</a:string>
    <a:string>23328</a:string>
  </ZipCodes>
</ZipCodesResponse>