Postal Address Verification API

GetCityNamesForZipCode

The GetCityNamesForZipCode method returns all possible city names for a given ZIP Code.

Endpoint

GET:
https://pav3.esendex.us/PavService.svc/GetCityNamesForZipCode?ZipCode={ZIPCODE}&LicenseKey={LICENSEKEY}

Syntax

GetCityNamesForZipCode(ZipCode, LicenseKey)

Request Parameters

Parameter NameDescriptionData TypeRequiredSample Value
ZipCodeZIP Code.StringTrue02861
LicenseKeyYour license key.StringTrue00000000-0000-0000-0000-000000000000

Response

Returns: CityNamesResponse 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 WSDL;

var config = PavServiceClient.EndpointConfiguration.pavws_secure;
var client = new PavServiceClient(config);
var zipCode = "02861";
var licenseKey = "YOUR_LICENSE_KEY";
var response = await client.GetCityNamesForZipCodeAsync(zipCode, licenseKey);

var returnCodeDescription = response.ReturnCode switch
{
    0 => "Success",
    1 => "Invalid input",
    2 => "Invalid license key",
    3 => "No match",
    _ => "Unknown return code"
};

Console.WriteLine($"Return Code: {response.ReturnCode} - {returnCodeDescription}");

if (response.CityNames is not null)
{
    foreach (var city in response.CityNames)
    {
        Console.WriteLine($"City Name: {city.Name}");
    }
}

Console.ReadLine();

JavaScript

const params = new URLSearchParams({
    'ZipCode': '02861',
    'LicenseKey': '00000000-0000-0000-0000-000000000000'
});

const url = 'https://pav3.esendex.us/PavService.svc/GetCityNamesForZipCode?' + params.toString();

const options = {
    headers: {
        'Accept': 'application/json'
    }
};

const response = await fetch(url, options);
const json = await response.json();

console.log(json);

JSON Response

{
  "CityNames": [
    {
      "IsDefault": false,
      "IsMailing": true,
      "Name": "PRINCESS ANNE"
    },
    {
      "IsDefault": false,
      "IsMailing": true,
      "Name": "VA BEACH"
    },
    {
      "IsDefault": true,
      "IsMailing": true,
      "Name": "VIRGINIA BEACH"
    }
  ],
  "ReturnCode": 0
}

PHP with cURL

<?php
$client = new SoapClient('https://pav3.esendex.us/PavService.svc?wsdl');
$param = array(
  'ZipCode' => '23320'
  , 'LicenseKey' => 'YOUR LICENSE KEY'
);
$result = $client->GetCityNamesForZipCode($param);

echo "<pre>";
print_r($result);
echo "</pre>";
?>

Python

import httpx

headers = {"Accept": "application/json"}
url = "https://pav3.esendex.us/PavService.svc/GetCityNamesForZipCode"

request = {
    "ZipCode": "02861",
    "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/GetCityNamesForZipCode')

params = {
  'ZipCode': '02861',
  '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

<CityNamesResponse xmlns="pav3.esendex.us" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <CityNames>
    <City>
      <IsDefault>false</IsDefault>
      <IsMailing>true</IsMailing>
      <Name>PRINCESS ANNE</Name>
    </City>
    <City>
      <IsDefault>false</IsDefault>
      <IsMailing>true</IsMailing>
      <Name>VA BEACH</Name>
    </City>
    <City>
      <IsDefault>true</IsDefault>
      <IsMailing>true</IsMailing>
      <Name>VIRGINIA BEACH</Name>
    </City>
  </CityNames>
  <ReturnCode>0</ReturnCode>
</CityNamesResponse>

Let’s start sending, together.