Address
Information

USPS Web Tools™

Application Programming Interface

User’s Guide

Document Version 4.0 (2/01/2015)

 

 

United States Postal Service Logo 

 

 


 

 


Table of Contents

1.0       Introduction To Web Tools. 2

Before you get started: 2

Important Notice: User ID.. 2

Important Notice: Address Information API 3

1.2 Error Responses. 3

2.0       Address Standardization Web Tool 4

Address Standardization Web Tool Transaction Procedures. 4

Step 1: Build the XML Request 4

Step 2: Make the Internet Connection & Send the XML Request 6

Step 3: Unpack the XML Response. 6

3.0       ZIP Code Lookup Web Tool 8

ZIP Code Lookup Web Tool Transaction Procedures. 8

Step 1: Build the XML Request 8

Step 2: Make the Internet Connection & Send the XML Request 10

Step 3: Unpack the XML Response. 10

4.0       City/State Lookup Web Tool 12

City/State Lookup Web Tool Transaction Procedures. 12

Step 1: Build the XML Request 12

Step 2: Make the Internet Connection & Send the XML Request 13

Step 3: Unpack the XML Response. 13

 


1.0    Introduction To Web Tools

This document contains a Reference Guide to the Address Information Web Tools listed below. See the Developer’s Guide step-by-step instructions  to learn the administrative process for gaining access to the Web Tools APIs as well as the basic mechanism for calling the APIs and processing the results. The Developer’s Guide also contains information on testing and trouble-shooting.

§  Address /Standardization Web Tool, which corrects errors in street addresses, including abbreviations and missing information, and supplies ZIP Codes and ZIP Codes + 4.  It supports up to five lookups per transaction.  By eliminating address errors, you will improve overall package delivery service.

§  ZIP Code Lookup Web Tool, which returns the ZIP Code and ZIP Code + 4 corresponding to the given address, city, and state (use USPS state abbreviations).  The ZIP Code Lookup Web Tool processes up to five lookups per request.

§  City/State Lookup Web Tool returns the city and state corresponding to the given ZIP Code.  The City/State Lookup Web Tool processes up to five lookups per request.

Note: The Request Parameter sections present the XML input tags for generating live requests along with the restrictions on the values allowed. An error message will be returned if an incorrect value is entered.  Also, be aware of the maximum character amounts allowed for some tags.  If the user enters more than those amounts, an error will not be generated. The Web Tool will simply pass in the characters up to the maximum amount allowed and disregard the rest.  This is important since the resulting value could prevent a correct response.

When building the XML request, pay particular attention to the order and case for tags. An error message will be returned if an incorrect value is entered.  Remember that all data and attribute values in this document are for illustration purposes and are to be replaced by your actual values. For instance, a line of sample code may be:

<State>MD</State>

In this instance, you will replace “MD” with the state abbreviation for the address location.

Before you get started:

For information on registering and getting started with Web Tools, please refer to the Step-By-Step guide found on the Technical Documentation section of the Web Tools page on usps.com/webtools.

Important Notice: User ID

The Web Tools User ID provided is for you and your company to use when requesting data via the Internet from the U.S. Postal Service API servers.  As per the Terms and Conditions of Use Agreement you agreed to during the Web Tools registration process, you are responsible to maintain the confidentiality of your User ID as specified.  You may not package any APIs with your User ID for resale or distribution to others.  The U.S. Postal Service does not prohibit the reuse and/or distribution of the API documentation (User's Guide) with sample code in order to generate awareness, encourage use or provide ease-of-use to customers or affiliates.

Warning - If the U.S. Postal Service discovers use of the same User ID from more than one web site, all users will be subject to loss of access to the USPS production server and/or termination of the licenses granted under the Terms and Conditions of Use.

Important Notice: Address Information API

The Address Validation APIs can be used in conjunction with USPS SHIPPING OR MAILING SERVICES ONLY. The Address API must only be used on an individual transactional basis, i.e. not batch processing or cleansing of a database, but as a customer enters the information into a form on a website. Failure to comply with these terms and conditions can result in termination of USPS API access without prior notice.         

1.2 Error Responses

Error conditions are handled at the main XML document level.  When parsing, it is best to check for an error document first before checking for good data.  Error documents have the following format:

<Error>

<Number></Number>

<Source></Source>

<Description></Description>

<HelpFile></HelpFile>

<HelpContext></HelpContext>

</Error>

Where:

§  Number = the error number generated by the Web Tools server.

§  Source = the component and interface that generated the error on the Web Tools server.

§  Description = the error description.

§  HelpFile = [reserved for future use].

§  HelpContext = [reserved for future use].

For Web Tools that can handle multiple transactions, the error conditions for requests for multiple responses to be returned together are handled at the response level.  For example: a Web Tool developer sends a request for rates for two packages.  If the addresses are non-existent, an “Error document” is returned to the user.  On the other hand, if the address for the first package is acceptable but not the second, the response document contains the information for the first address, but under the XML tag for the second address there is an error tag.

Errors that are further down in the hierarchy also follow the above format.

2.0    Address Standardization Web Tool

The Address Standardization Web Tool corrects errors in street addresses, including abbreviations and missing information, and supplies ZIP Codes and ZIP Codes + 4.  It supports up to five lookups per transaction.  By eliminating address errors, you will improve overall package delivery service.

Address Standardization Web Tool Transaction Procedures

The illustration below shows the transactional flow of information to and from the USPS Address Standardization Web Tool server:

Address Standardization Web Tool Server
Laptop computer icon. Inputs via XML request are address I D # (up to 5), recipient name, recipient address and recipient zip code(s).
Server icon.  Server tasks are looks up in address management system, gets correct address and builds XML response.
Laptop computer icon.  Outputs via XML response is corrected address(es).

Step 1: Build the XML Request

API Signature

Scheme

Host

Path

API

XML

http://

production.shippingapis.com

/ShippingAPI.dll

?API=Verify

&XML=(see below)

 

 XML Tags

The table below presents the XML input tags for generating live requests and the restrictions on the values allowed.  An error message will be returned if an incorrect value is entered.  Also, be aware of the maximum character amounts allowed for some tags.  If the user enters more than those amounts, an error will not be generated.  The Web Tool will simply pass in the characters up to the maximum amount allowed and disregard the rest.  This is important since the resulting value could prevent a correct response.

XML Tag

Required/Optional

Description & Values Allowed

<AddressValidateRequest

Required

Input tag exactly as presented.

…USERID=”userid”>

Required

Use user ID provided with registration.

<IncludeOptionalElements>

Optional Tag/

Optional Value

Flag to return Delivery Point and other optional elements in the future

<ReturnCarrierRoute>

Optional Tag/

Optional Value

Flag to return Carrier Route – true/false

e.g., <AddressValidateRequest USERID="yourID">

Tags within the above defined call are as follows:

XML Tag

Required/

Optional

Description & Values Allowed

<Address ID='#'>

Required Tag/

Required Value

Up to 5 address verifications can be included per transaction.

For example: <Address ID="0"></Address>

<FirmName>

Required Tag/

Optional Value

Maximum characters allowed: 38

For example:  <FirmName>XYZ Corp.</FirmName>

<Address1>

Required Tag/

Optional Value

Address Line 1 is used to provide an apartment or suite number, if applicable.  Maximum characters allowed: 38

For example: <Address1></Address1>

<Address2>

Required Tag/

Required Value

Street address.

Maximum characters allowed: 38

For example: <Address2>6406 Ivy </Address2>

<City>

Required Tag/

Optional Value

(see box at right)

Maximum characters allowed: 15.  Either <City> and <State> or <Zip5> are required.

For example: <City>Greenbelt</City>

<State>

Required Tag/

Optional Value

(see box at right)

Maximum characters allowed: 2. Either <City> and <State> or <Zip5> are required.

For example: <State>MD</State>

<Urbanization>

Optional Tag/

Optional Value

(see box at right)

Maximum characters allowed: 28. For Puerto Rico addresses only.

For example: <Urbanization></Urbanization>

<Zip5>

Required Tag/

Optional Value

(see box at right)

Input tag exactly as presented, not all caps.  Maximum characters allowed: 5. Either <City> and <State> or <Zip5> are required.

For example:  <Zip5></Zip5>

<Zip4>

Required Tag/

Optional Value

Input tag exactly as presented, not all caps.  Maximum characters allowed: 4

For example: <Zip4></Zip4>

URL

All users will receive access to Address Information APIs upon registration and agreement to terms and conditions of use. Users will need to enter their own User ID in the examples shown below.

XML Request Example                                  

The  XML request should be in the following form and sequence:

<AddressValidateRequest USERID="XXXXX">

  <IncludeOptionalElements>true</IncludeOptionalElements>

  <ReturnCarrierRoute>true</ReturnCarrierRoute>

  <Address ID="0">  

    <FirmName />   

    <Address1 />   

    <Address2>205 bagwell ave</Address2>   

    <City>nutter fort</City>   

    <State>wv</State>   

    <Zip5></Zip5>   

    <Zip4></Zip4> 

  </Address>      

</AddressValidateRequest>

Step 2: Make the Internet Connection & Send the XML Request

This step involves four separate functions:

  1. Making the connection to the USPS Shipping Web Tools server.
  2. Sending the request (whether Perl, ASP, or any other language).
  3. Receiving the response from the Web Tools server.
  4. Closing the Internet connection.

If you have recently registered, the registration e-mail will have the name of the server.  If you are an existing user and do not have the name of the server, please contact the ICCC.  When sending the XML request, the Web Tool name must be specified.  The server name can be found in your Web Tools registration e-mail.  The Web Tool name is Verify.  The format of the XML transaction is:

https://servername/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="username">…….</AddressValidateRequest>

Step 3: Unpack the XML Response

When the USPS Shipping Web Tools returns a response, it will either return a successful response document or an error document. 

XML Output from Unpacked Response

After unpacking the XML response, you will have the output from your request—an XML response with the following tags:

Output

XML Tag

Type of Response

<AddressValidateResponse>

Address Verification Number

<Address ID='#'>

Name of Firm

<FirmName>

Address Line 1

<Address1>

Address Line 2

<Address2>

City

<City>

State

<State>

Urbanization

<Urbanization>

ZIP Code

<Zip5>

ZIP Code + 4

<Zip4>

Delivery Point

<DeliveryPoint>

Carrier Route

<CarrierRoute>

Error Response Message when multiple addresses found*

<ReturnText>

*This output is only returned when the address entered results in multiple locations being found by the Shipping API server, but a default address exists.  The text of the message will read: “Default address: The address you entered was found but more information is needed (such as an apartment, suite, or box number) to match to a specific address.”

 XML Response

The Address Standardization Web Tool returns the following information to the supplied address:

<AddressValidateResponse>

  <Address ID="0">

    <Address2>205 BAGWELL AVE</Address2>

    <City>NUTTER FORT</City>

    <State>WV</State>

    <Zip5>26301</Zip5>

    <Zip4>4322</Zip4>

    <DeliveryPoint>05</DeliveryPoint>

    <CarrierRoute>C025</CarrierRoute>

  </Address>

</AddressValidateResponse>

If an error message is returned, refer to the Error Responses section for an explanation.

 


3.0    ZIP Code Lookup Web Tool

The ZIP Code Lookup Web Tool returns the ZIP Code and ZIP Code + 4 corresponding to the given address, city, and state (use USPS state abbreviations).  The ZIP Code Lookup Web Tool processes up to five lookups per request.

ZIP Code Lookup Web Tool Transaction Procedures

The illustration below shows the transactional flow of information to and from the USPS ZIP Code Lookup Web Tool server:

City/State Lookup Web Tool Server
Laptop computer icon. Inputs via XML request are zip code I D # (up to 5)  and zip code.
Server icon.  Server tasks are gets data from address management system, gets city and state and builds XML response.
Laptop computer icon.  Outputs via XML response are zip code, city and state.

Step 1: Build the XML Request

API Signature

Scheme

Host

Path

API

XML

http://

production.shippingapis.com

/ShippingAPI.dll

?API= ZipCodeLookup

&XML=(see below)

 

 XML Tags

The table below presents the XML input tags for generating  requests and the restrictions on the values allowed.  An error message will be returned if an incorrect value is entered.  Also, be aware of the maximum character amounts allowed for some tags.  If the user enters more than those amounts, an error will not be generated.  The Web Tool will simply pass in the characters up to the maximum amount allowed and disregard the rest.  This is important since the resulting value could prevent a correct response.

XML Tag

Required/Optional

Description & Values Allowed

<ZipCodeLookupRequest

Required

Input tag exactly as presented.

…USERID=”userid”>

Required

Use user ID provided with registration.

e.g., <ZipCodeLookupRequest USERID="yourID">

Tags within the above defined call are as follows:

 

XML Tag

Required/

Optional

 

Description & Values Allowed

<Address ID='#'>

Required Tag/

Required Value

Up to 5 address verifications can be included per transaction.

For example: <Address ID="0"></Address>

<FirmName>

Required Tag/

Optional Value

Maximum characters allowed: 38

For example:  <FirmName>XYZ Corp.</FirmName>

<Address1>

Required Tag/

Optional Value

Address Line 1 is used to provide an apartment or suite number, if applicable.  Maximum characters allowed: 38

For example: <Address1></Address1>

<Address2>

Required Tag/

Required Value

Street address.

Maximum characters allowed: 38

For example: <Address2>6406 Ivy </Address2>

<City>

Required Tag/

Required Value

Maximum characters allowed: 15

For example: <City>Greenbelt</City>

<State>

Required Tag/

Required Value

Maximum characters allowed: 2

For example: <State>MD</State>

 URL

All users will receive access to Address Information APIs upon registration and agreement to terms and conditions of use. Users will need to enter their own User ID in the examples shown below.

 XML Request Example

The  XML request should be in the following form:

<ZipCodeLookupRequest USERID=”xxxxxxxx”>

<Address ID='0'>

<FirmName>XYZ Corp.</FirmName>

<Address1></Address1>

<Address2>6406 Ivy</Address2>

<City>Greenbelt</City>

<State>MD</State>

</Address>

<Address ID='1'>

<FirmName>ABC Company</FirmName>

<Address1>Apt/Suite 2</Address1>

<Address2>435 S Main Street</Address2>

<City>Los Angeles</City>

<State>CA</State>

</Address>

</ZipCodeLookupRequest>


 

Step 2: Make the Internet Connection & Send the XML Request

This step involves four separate functions:

  1. Making the connection to the USPS Shipping Web Tools server.
  2. Sending the request (whether Perl, ASP, or any other language).
  3. Receiving the response from the Web Tools server.
  4. Closing the Internet connection.

If you have recently registered, the registration e-mail will have the name of the server.  If you are an existing user and do not have the name of the server, please contact the ICCC.  When sending the XML request, the Web Tool name must be specified.  The server name can be found in your Web Tools registration e-mail.  The Web Tool name is ZipCodeLookup.  The format of the XML transaction is:

http://production/ShippingAPI.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest USERID="username">…….</ZipCodeLookupRequest>

Step 3: Unpack the XML Response

When the USPS Shipping Web Tools returns a response, it will either return a successful response document or an error document. 

XML Output from Unpacked Response

Output

XML Tag

Type of Response

<ZipCodeLookupResponse>

Address ID Number

<Address ID='#'>

Name of Firm

<FirmName>

Address Line 1

<Address1>

Address Line 2

<Address2>

City

<City>

State

<State>

ZIP Code

<Zip5>

ZIP Code + 4

<Zip4>

 XML Output Example

The ZIP Code Lookup Web Tool returns the following information to the user.

<?xml version="1.0" ?>

<ZipCodeLookupResponse>

<Address ID="0">

<FirmName>XYZ CORP.</FirmName>

<Address2>6406 IVY LN</Address2>

<City>GREENBELT</City>

<State>MD</State>

<Zip5>20770</Zip5>

<Zip4>1441</Zip4>

</Address>

<Address ID="1">

<FirmName>ABC COMPANY</FirmName>

<Address1>Apt/Suite 2</Address1>

<Address2>435 S MAIN ST</Address2>

<City>LOS ANGELES</City>

<State>CA</State>

<Zip5>90013</Zip5>

<Zip4>1310</Zip4>

</Address>

</ZipCodeLookupResponse>

 


4.0    City/State Lookup Web Tool

The City/State Lookup Web Tool returns the city and state corresponding to the given ZIP Code.  This Web Tool processes up to five lookups per request.

City/State Lookup Web Tool Transaction Procedures

The illustration below shows the transactional flow of information to and from the USPS City/State Lookup Web Tools server:

City/State Lookup Web Tool Server
Laptop computer icon. Inputs via XML request are zip code I D # (up to 5)  and zip code.
Server icon.  Server tasks are gets data from address management system, gets city and state and builds XML response.
Laptop computer icon.  Outputs via XML response are zip code, city and state.

Step 1: Build the XML Request

API Signature

Scheme

Host

Path

API

XML

http://

production.shippingapis.com

/ShippingAPI.dll

?API= CityStateLookup

&XML=(see below)

XML Tags

The table below presents the XML input tags for generating  requests and the restrictions on the values allowed.  An error message will be returned if an incorrect value is entered.  Also, be aware of the maximum character amounts allowed for some tags.  If the user enters more than those amounts, an error will not be generated.  The Web Tool will simply pass in the characters up to the maximum amount allowed and disregard the rest.  This is important since the resulting value could prevent a correct response.

XML Tag

Required/Optional

Description & Values Allowed

<CityStateLookupRequest

Required

Input tag exactly as presented.

…USERID=”userid”>

Required

Use user ID provided with registration.

 

Tags within the above defined call are as follows:

 

XML Tag

Required/

Optional

 

Description & Values Allowed

<ZipCode ID='#'>

Required Tag/

Required Value

Up to five ZIP Codes can be included per transaction.

For example: <ZipCode ID="0"></ZipCode ID>

<Zip5>

Required Tag/

Required Value

Input tag exactly as presented, not all caps.  Maximum characters allowed: 5

For example:  <Zip5>90210</Zip5>

 URL

All users will receive access to Address Information APIs upon registration and agreement to terms and conditions of use. Users will need to enter their own User ID in the examples shown below.

 XML Request Example

The XML request should be in the following form and sequence:

<CityStateLookupRequest USERID=”xxxxxxxx”>

<ZipCode ID="0">

<Zip5>90210</Zip5>

</ZipCode>

<ZipCode ID="1">

<Zip5>20770</Zip5>

</ZipCode>

</CityStateLookupRequest>

Step 2: Make the Internet Connection & Send the XML Request

This step involves four separate functions:

1.   Making the connection to the USPS Shipping Web Tools server.

2.   Sending the request (whether Perl, ASP, or any other language).

3.   Receiving the response from the Web Tools server.

4.   Closing the Internet connection.

If you have recently registered, the registration e-mail will have the name of the server.  If you are an existing user and do not have the name of the server, please contact the ICCC.  When sending the XML request, the Web Tool name must be specified.  The server name can be found in your Web Tools registration e-mail.  The Web Tool name is CityStateLookup.  The format of the XML transaction is:

https://production/ShippingAPI.dll?API=CityStateLookup&XML=<CityStateLookupRequest USERID="username">…….</CityStateLookupRequest>

Step 3: Unpack the XML Response

When the USPS Shipping Web Tools returns a response, it will either return a successful response document or an error document.

XML Output from Unpacked Response

After unpacking the XML response, you will have the output from your request—an XML response with the following tags:

Output

XML Tag

Type of Response

<CityStateLookupResponse

ZIP Code Lookup Number

<ZipCode ID='#'>

ZIP Code of City or State

<Zip5>

City for Requested ZIP Code

<City>

State for requested ZIP Code

<State>

 XML Response

The City/State Lookup Web Tool returns the following information for the supplied address:

 

<CityStateLookupResponse>

<ZipCode ID="0">

<Zip5>90210</Zip5>

<City>BEVERLY HILLS</City>

<State>CA</State>

</ZipCode>

<ZipCode ID="1">

<Zip5>20770</Zip5>

<City>GREENBELT</City>

<State>MD</State>

</ZipCode>

</CityStateLookupResponse>