国内邮件
服务
标准

Version 2.7 (1/23/2019)

 

USPS Web Tools™

Application Programming Interface

User’s Guide

 

 

 

 

 

 

 

United States Postal Service 徽标
 

 

 


 


Contents

1.0        Introduction to Web Tools. 3

1.1       Before you get started: 3

1.2       Overview.. 3

1.3       API Signature. 3

1.4       Tag Descriptions - Request 4

1.4.1        Sample Request 5

1.5       Tag Descriptions - Response. 6

1.5.1        Sample Responce. 6

2.0        USPS Package Services API 7

2.1       Overview.. 7

2.2       API Signature. 7

2.3       Tag Descriptions - Request 7

2.3.1        Sample Request 9

2.4       Tag Descriptions – Response. 9

2.4.1        Sample Response. 9

3.0        USPS First Class Mail API 11

3.1       Overview.. 11

3.2       API Signature. 11

3.3       Tag Descriptions - Request 11

3.3.1        Sample Request 13

3.4       Tag Descriptions – Response. 13

3.4.1        Sample Response. 13

4.0        USPS Express Mail Service Commitments API 14

4.1       Overview.. 14

4.2       API Signature. 14

4.3       Tag Descriptions - Request 14

4.3.1        Sample Request 15

4.4       Tag Descriptions – Response. 16

4.4.1        Sample Requests. 18

5.0        Error Responses. 20

 


1.0   Introduction to Web Tools

This document contains a Reference Guide to the Domestice Service Standards APIs. See the Developer’s Guide 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.

 

注意: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:

 

<DestinationZIP> 12345 </ DestinationZIP >

 

In this instance, you will replace “12345” with the destination zip code for your request.

1.1    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. USPS Priority Mail API.

1.2    Overview

The Priority Mail Service Standards Web Tool receives requests and returns the number of days (on average) it will take a Priority Mail package to arrive at its destination. Ensure that end-users understand that these are service standards and not guaranteed commitments.. The Priority Mail Service Standards Web Tool processes a single request.

1.3    API Signature

Secure

Scheme

Host

小道

API

XML

https://

secure.shippingapis.com

/ShippingAPI.dll?

API=PriorityMail

&XML=(see below)

http://

production.shippingapis.com

/ShippingAPI.dll?

API=PriorityMail

&XML=(see below)

 

 

 

1.4    Tag Descriptions - Request

Tag Name

Occurs

描述

类型

PriorityMailRequest

需要 

 

(group)

PriorityMailRequest USERID

需要

This attribute specifies your Web Tools ID. See the Developer's Guide for information on obtaining your USERID.

 

例如:

<TrackRequest USERID=”yourID”>

string

PriorityMailRequest / OriginZip

需要

Origination and destination ZIP Codes must be valid.  Either  the first 3 digits or first 5 digits of the Zip Code are entered between the open tag and close tag. 

 

例如: <OriginZip>90210</OriginZip>

string

PriorityMailRequest / DestinationZip

需要

Origination and destination ZIP Codes must be valid and must be 5 digits.

 

例如: <DestinationZip>20770</DestinationZip>

string

PriorityMailRequest / DestinationType

optional

Destination Type for package. 

 

Valid Values:

“1” = PO-Addressee – Street (Default Value)

“2” = PO-Addressee – PO Box

“3” = Hold For Pick-up

 

例如: <DestinationType>1</DestinationType>

string

PriorityMailRequest / PMGuarantee

optional

Default “N”

boolean

PriorityMailRequest

required once

 

(alias)

PriorityMailRequest / ClientType

optional

Client Type to designate sender.

Client

价值

POS

001

SSK (APC)

002

PTR

003

WebTools

004

CARS

005

RSS

006

PC Postage(计算机邮资)

007

CNS

008

CNS-B

009

CCC

010

eVS

011

PASS

012

PostalOne

013

Rate Engine

014

EASR

015

MetroPost

016

夫人

017

PFSC

018

Call Tag

019

PackageIntercept

020

RRAM

021

SBP

022

移动

023

 

注意:If the tag is not sent, a default value of “4” will be used.

 

例如: <ClientType>8</ClientType>

string

1.4.1   Sample Request

All requests should hit the http://production.shippingapis.com/ShippingAPI.dll end point with the API=PriorityMail and XML=<the sample XML request below> key value pairs using either a HTTP POST or a HTTP GET.

Test XML Request:

<PriorityMailRequest USERID=”xxxxxxxx>

              <OriginZip>90201</OriginZip>

              <DestinationZip>21114</DestinationZip>

</PriorityMailRequest> 

 


 

1.5    Tag Descriptions - Response

Tag Name

Occurs

描述

类型

PriorityMailResponse

需要 

 

(group)

PriorityMailResponse / OriginZip

需要

OriginationZip sent in request.

 

string

PriorityMailResponse / DestinationZip

需要

DestinationZip sent in request.

 

string

PriorityMailResponse / Days

optional

Numbers of days expected to deliver.

 

string

PriorityMailResponse / IsGuaranteed

optional

Is the delivery guaranteed.

string

PriorityMailResponse / Message

optional

Service Standards Messaging. Appears when applicable.

string

PriorityMailResponse / EffectiveAcceptanceDate

optional

Effective Acceptance Date is returned when <DestinationType> is specified in the request.

string

PriorityMailResponse / ScheduledDeliveryDate

optional

Scheduled Delivery Date is returned when <DestinationType> is specified in the request.

string

PriorityMailResponse / Error

optional

(group)

 

PriorityMailResponse / Error / ErrorDescription

optional

Error Description

string

PriorityMailResponse / Error / ReturnCode

optional

Return Code Description

string

PriorityMailResponse

需要

 

(group)

 

1.5.1   Sample Responce

Test XML Response:

<PriorityMailResponse>

<OriginZip>90201</OriginZip>

<DestinationZip>21114</DestinationZip>

<Days>4</Days>

</PriorityMailResponse>


 

2.0   USPS Package Services API

2.1    Overview

The Package Services Service Standards Web Tool receives requests and returns the average number of days it will take a package to arrive at its destination.  There are four types of Package Services: Standard Post, Bound Printed Matter, Library Mail, and Media Mail.  The Package Services Service Standards Web Tool processes a single request.  Ensure that end-users understand that these are service standards and not guaranteed commitments.

2.2    API Signature

Scheme

Host

小道

API

XML

https://

secure.shippingapis.com

/ShippingAPI.dll?

API=StandardB

&XML=(see below)

http://

production.shippingapis.com

/ShippingAPI.dll?

API=StandardB

&XML=(see below)

 

2.3    Tag Descriptions - Request

Tag Name

Occurs

描述

类型

StandardBlRequest

需要 

 

(group)

StandardBRequest USERID

需要

This attribute specifies your Web Tools ID. See the Developer's Guide for information on obtaining your USERID.

 

例如: <TrackRequest USERID=”yourID”>

string

StandardBRequest / OriginZip

需要

Origination and destination ZIP Codes must be valid.  Either  the first 3 digits or first 5 digits of the Zip Code are entered between the open tag and close tag. 

 

例如: <OriginZip>90210</OriginZip>

string

StandardBRequest / DestinationZip

需要

Origination and destination ZIP Codes must be valid and must be 5 digits.

 

例如: <DestinationZip>20770</DestinationZip>

string

StandardBRequest

required once

 

(alias)

StandardBRequest / DestinationType

optional

Destination Type for package. 

 

Valid Values:

“1” = PO-Addressee – Street (Default Value)

“2” = PO-Addressee – PO Box

“3” = Hold For Pick-up

 

例如: <DestinationType>1</DestinationType>

String

StandardBRequest / ClientType

optional

Client Type to designate sender.

 

Client

价值

POS

001

SSK (APC)

002

PTR

003

WebTools

004

CARS

005

RSS

006

PC Postage(计算机邮资)

007

CNS

008

CNS-B

009

CCC

010

eVS

011

PASS

012

PostalOne

013

Rate Engine

014

EASR

015

MetroPost

016

夫人

017

PFSC

018

Call Tag

019

PackageIntercept

020

RRAM

021

SBP

022

移动

023

 

注意:If the tag is not sent, a default value of “4” will be used.

 

例如: <ClientType>8</ClientType>

string

StandardBlRequest

需要

 

(group)

 

 

 

2.3.1   Sample Request

All requests should hit the http://production.shippingapis.com/ShippingAPI.dll end point with the API=StandardB and XML=<the sample XML request below> key value pairs using either a HTTP POST or a HTTP GET.

Test XML Request:

<StandardBRequest USERID=”xxxxxxxx>

              <OriginZip>90201</OriginZip>

              <DestinationZip>21114</DestinationZip>

              <ClientType>8</ClientType>

</ StandardBRequest > 

2.4    Tag Descriptions – Response

Tag Name

Occurs

描述

类型

StandardBResponse

需要 

 

(group)

StandardBResponse / OriginZip

需要

OriginationZip sent in request.

 

string

StandardBResponse / DestinationZip

需要

DestinationZip sent in request.

 

string

StandardBResponse / Days

optional

Numbers of days expected to deliver.

 

string

StandardBResponse / Message

optional

Service Standards Messaging. Appears when applicable.

string

StandardBResponse / EffectiveAcceptanceDate

optional

Effective Acceptance Date is returned when <DestinationType> is specified in the request.

string

StandardBResponse / ScheduledDeliveryDate

optional

Scheduled Delivery Date is returned when <DestinationType> is specified in the request.

string

StandardBResponse / Error

optional

 

(group)

StandardBResponse / Error / ErrorDescription

optional

Error Description

string

StandardBResponse / Error / ReturnCode

optional

Return Code

string

StandardBResponse

需要

 

(group)

 

 

 

2.4.1   Sample Response

Test XML Response:

< StandardBRequest >

<OriginZip>90201</OriginZip>

<DestinationZip>21114</DestinationZip>

<Days>7</Days>

</ StandardBRequest >

 

3.0   USPS First Class Mail API

3.1    Overview

The First Class Mail Service Standards Web Tool receives requests and returns the average number of days it will take a package to arrive at its destination.  The First Class Mail Service Standards Web Tool processes a single request.  Ensure that end-users understand that these are service standards and not guaranteed commitments.

3.2    API Signature

Scheme

Host

小道

API

XML

http://

production.shippingapis.com

/ShippingAPI.dll?

API=FirstClassMail

&XML=(see below)

3.3    Tag Descriptions - Request

Tag Name

Occurs

描述

类型

FirstClassMailRequest

需要 

 

(group)

FirstClassMailRequest USERID

需要

This attribute specifies your Web Tools ID. See the Developer's Guide for information on obtaining your USERID.

 

例如:

<TrackRequest USERID=”yourID”>

string

FirstClassMailRequest / OriginZip

需要

Origination and destination ZIP Codes must be valid.  Either  the first 3 digits or first 5 digits of the Zip Code are entered between the open tag and close tag. 

 

例如: <OriginZip>90210</OriginZip>

string

FirstClassMailRequest / DestinationZip

需要

Origination and destination ZIP Codes must be valid and must be 5 digits.

 

例如: <DestinationZip>20770</DestinationZip>

string

FirstClassMailRequest / DestinationType

optional

Destination Type for package. 

 

Valid Values:

“1” = PO-Addressee – Street (Default Value)

“2” = PO-Addressee – PO Box

“3” = Hold For Pick-up

 

例如: <DestinationType>1</DestinationType>

String

FirstClassMailRequest / ClientType

optional

 

string

FirstClassMailRequest

required once

 

(alias)


 

3.3.1   Sample Request

All requests should hit the http://production.shippingapis.com/ShippingAPI.dll end point with the API=FirstClassMail and XML=<the sample XML request below> key value pairs using either a HTTP POST or a HTTP GET.

Test XML Request:

<FirstClassMailRequest USERID=”xxxxxxxx>

              <OriginZip>90201</OriginZip>

              <DestinationZip>21114</DestinationZip>

              </FirstClassMailRequest> 

3.4    Tag Descriptions – Response

Tag Name

Occurs

描述

类型

FirstClassMailResponse

需要 

 

(group)

FirstClassMailResponse / OriginZip

需要

OriginationZip sent in request.

 

string

FirstClassMailResponse / DestinationZip

需要

DestinationZip sent in request.

 

string

FirstClassMailResponse / Days

optional

Numbers of days expected to deliver.

 

string

FirstClassMailResponse / Message

optional

Service Standards Messaging. Appears when applicable.

string

FirstClassMailResponse / EffectiveAcceptanceDate

optional

Effective Acceptance Date is returned when <DestinationType> is specified in the request.

string

FirstClassMailResponse / ScheduledDeliveryDate

optional

Scheduled Delivery Date is returned when <DestinationType> is specified in the request.

string

3.4.1   Sample Response

Test XML Response:

<FirstClassMailResponse>

<OriginZip>90201</OriginZip>

<DestinationZip>21114</DestinationZip>

<Days>3</Days>

</FirstClassMailResponse>

 


 

4.0   USPS Express Mail Service Commitments API

4.1    Overview

The Express Mail Service Commitments Web Tool provides delivery commitments for Express Mail packages.  A user provides an origination and a destination ZIP Code and an optional current or future date that the package will be shipped.  The Web Tool returns all the Express Mail Service Commitments for the given locations to include package drop-off information.

4.2    API Signature

Scheme

Host

小道

API

XML

http://

production.shippingapis.com

/ShippingAPI.dll?

API=ExpressMailCommitment

&XML=(see below)

4.3    Tag Descriptions - Request

Tag Name

Occurs

描述

类型

ExpressMailCommitmentRequest

需要 

 

(group)

ExpressMailCommitmentRequest USERID

需要

This attribute specifies your Web Tools ID. See the Developer's Guide for information on obtaining your USERID.

 

例如:

<TrackRequest USERID=”yourID”>

string

ExpressMailCommitmentRequest / OriginZIP

需要

5 Digit ZIP Code of the package destination. 

 

例如: <OriginZIP>90210</OriginZIP>

string

ExpressMailCommitmentRequest / DestinationZIP

需要

Origination and destination ZIP Codes must be valid and must be 5 digits.

 

例如: <DestinationZIP>20770</DestinationZIP>

string

ExpressMailCommitmentRequest / Date

需要

Date package is shipped.  Can be left blank.  Can use formats MM/DD/YYYY or DD-MMM-YYYY.

 

例如:

<Date>05-May-2014</Date>

string

ExpressMailCommitmentRequest / DropOffTime

optional

Time package is shipped.  This tag can be omitted or left blank.  Use format HH:MM such as 13:30.

 

例如:

< DropOffTime >15:00</ DropOffTime >

string

ExpressMailCommitmentRequest / ReturnDates

optional

Indicates if Scheduled Delivery and Effective Acceptance dates should be returned.  Specify ‘true’ or ‘false’

 

例如:

<ReturnDates>true</ReturnDates>

string

ExpressMailCommitmentRequest / PMGuarantee

optional

Indicator to display Guarantee information for applicable service types.

 

Valid Values:

“Y” = Yes, display

“N” = No, do not display (Default Value)

String

ExpressMailCommitmentRequest

required once

 

(alias)

4.3.1   Sample Request

All requests should hit the http://production.shippingapis.com/ShippingAPI.dll end point with the API=ExpressMailCommitment and XML=<the sample XML request below> key value pairs using either a HTTP POST or a HTTP GET.

Test XML Request:

<ExpressMailCommitmentRequest USERID= ”xxxxxxxx>

              <OriginZIP>90201</OriginZIP>

              <DestinationZIP>21114</DestinationZIP>

              <Date></Date>

              <PMGuarantee>Y</PMGuarantee>

              <ClientType>8</ClientType>

</ExpressMailCommitmentRequest> 


 

4.4    Tag Descriptions – Response

Tag Name

Occurs

描述

类型

ExpressMailCommitmentResponse

需要 

 

(group)

ExpressMailCommitmentResponse / OriginZip

需要

OriginationZip sent in request.

 

string

ExpressMailCommitmentResponse / OriginCity

需要

Originating City.

string

ExpressMailCommitmentResponse / OriginState

需要

Originating State.

string

ExpressMailCommitmentResponse / DestinationZip

需要

DestinationZip sent in request.

 

string

ExpressMailCommitmentResponse / DestinationCity

需要

Destinating City.

string

ExpressMailCommitmentResponse / DestinationState

需要

Destinating State.

string

ExpressMailCommitmentResponse / Date

需要

Date package shipped.

string

ExpressMailCommitmentResponse / Time

需要

Time.

string

ExpressMailCommitmentResponse / ExpeditedTransMessage

optional

Expedited Transportation Message. Returned when applicable and the request has the ReturnDates set to true.

string

ExpressMailCommitmentResponse / MsgCode

optional

Message Code. Returned when applicable and the request has the ReturnDates set to true.

string

ExpressMailCommitmentResponse / Msg

optional

Message Text. Returned when applicable and the request has the ReturnDates set to true.

string

ExpressMailCommitmentResponse / EffectiveAcceptanceDate

optional

Effective Acceptance Date. Returned when the request has the ReturnDates set to true.

string

ExpressMailCommitmentResponse / Commitment

optional

Holds the details of a commitment. Returned if valid.

(group)

ExpressMailCommitmentResponse / Commitment / Name

optional

Commitment Name

 

Valid Values:

‘Blank’

1-Day

2-Day

3-Day

DPO(指定邮局)

军事

string

ExpressMailCommitmentResponse / Commitment / Time

optional

Commitment Time. (eg: 3:00 PM)

string

ExpressMailCommitmentResponse / Commitment / Sequence

optional

Commitment Sequence

 

Valid Values:

Seq #     Service Standard

A0110   1-Day at 10:30 AM 

B0110   1-Day at 10:30 AM  HFPU

A0112  1-Day at 12:00 PM 

A0115   1-Day at 3:00 PM 

B0115   1-Day at 3:00 PM  HFPU

A0210   2-Day at 10:30 AM 

A0212   2-Day at 12:00 PM 

A0215   2-Day at 3:00 PM 

B0210  2-Day at 10:30 AM  HFPU

B0215   2-Day at 3:00 PM  HFPU

string

ExpressMailCommitmentResponse / Commitment / Location

optional

Groups drop off location information.

(group)

ExpressMailCommitmentResponse / Commitment / Location / ScheduledDeliveryDate

optional

预定投递日期。Returned when the request has the ReturnDates set to true.

string

ExpressMailCommitmentResponse / Commitment / Location / CutOff

optional

Cut-Off Time.

string

ExpressMailCommitmentResponse / Commitment / Location / Facility

optional

Facility Type

 

Valid Values:

 “POST OFFICE”

“PRIORITY MAIL EXPRESS COLLECTION BOX”

“AIR MAIL FACILITY”

string

ExpressMailCommitmentResponse / Commitment / Location / Street

optional

Facility Street

string

ExpressMailCommitmentResponse / Commitment / Location / City

optional

Facility City

string

ExpressMailCommitmentResponse / Commitment / Location / State

optional

Facility State

string

ExpressMailCommitmentResponse / Commitment / Location / ZIp

optional

Facility Zip Code

string

ExpressMailCommitmentResponse / Commitment / Location /  IsGuaranteed

optional

Indicates if Guaranee is offered. Will only be returned if the PMGuarantee in the request is set to “Y”.

 

Valid Values:

  “1” = Guaranteed

  “2” = No Guarantee

  “3” = Temporary No Guarantee

string

ExpressMailCommitmentResponse / Message

optional

Message indicating over 200 location, when there are more than the 200 returned.

string

4.4.1   Sample Requests

Test XML Response:

<ExpressMailCommitmentResponse>

  <OriginZIP>90201</OriginZIP>

  <OriginCity>BELL GARDENS</OriginCity>

  <OriginState>CA</OriginState>

  <DestinationZIP>21114</DestinationZIP>

  <DestinationCity>CROFTON</DestinationCity>

  <DestinationState>MD</DestinationState>

  <Date>3-Jul-2014</Date>

  <Time>7:51AM</Time>

  <EffectiveAcceptanceDate>2014-07-03</EffectiveAcceptanceDate>

  <Commitment>

    <CommitmentName>2-Day</CommitmentName>

    <CommitmentTime>下午 3:00</CommitmentTime>

    <CommitmentSequence>A0215</CommitmentSequence>

    <Location>

      <ScheduledDeliveryDate>2014-07-05</ScheduledDeliveryDate>

      <CutOff>下午 5:00</CutOff>

      <Facility>邮局</Facility>

      <Street>7001 GARFIELD AVE</Street>

      <City>BELL GARDENS</City>

      <State>CA</State>

      <Zip>90201</Zip>

      <IsGuaranteed>1</IsGuaranteed>

    </Location>

    <Location>

      <ScheduledDeliveryDate>2014-07-05</ScheduledDeliveryDate>

      <CutOff>下午 4:45</CutOff>

      <Facility>邮局</Facility>

      <Street>4619 ELIZABETH ST</Street>

      <City>CUDAHY</City>

      <State>CA</State>

      <Zip>90201</Zip>

      <IsGuaranteed>1</IsGuaranteed>

    </Location>

    <Location>

      <ScheduledDeliveryDate>2014-07-05</ScheduledDeliveryDate>

      <CutOff>下午 2:00</CutOff>

      <Facility>邮局</Facility>

      <Street>5555 BANDINI BLVD</Street>

      <City>BELL GARDENS</City>

      <State>CA</State>

      <Zip>90201</Zip>

      <IsGuaranteed>1</IsGuaranteed>

    </Location>

  </Commitment>

  <Commitment>

    <CommitmentName>2-Day</CommitmentName>

    <CommitmentTime>下午 3:00</CommitmentTime>

    <CommitmentSequence>B0215</CommitmentSequence>

    <Location>

      <ScheduledDeliveryDate>2014-07-07</ScheduledDeliveryDate>

      <CutOff>下午 5:00</CutOff>

      <Facility>邮局</Facility>

      <Street>7001 GARFIELD AVE</Street>

      <City>BELL GARDENS</City>

      <State>CA</State>

      <Zip>90201</Zip>

      <IsGuaranteed>1</IsGuaranteed>

    </Location>

    <Location>

      <ScheduledDeliveryDate>2014-07-07</ScheduledDeliveryDate>

      <CutOff>下午 4:45</CutOff>

      <Facility>邮局</Facility>

      <Street>4619 ELIZABETH ST</Street>

      <City>CUDAHY</City>

      <State>CA</State>

      <Zip>90201</Zip>

      <IsGuaranteed>1</IsGuaranteed>

    </Location>

    <Location>

      <ScheduledDeliveryDate>2014-07-07</ScheduledDeliveryDate>

      <CutOff>下午 2:00</CutOff>

      <Facility>邮局</Facility>

      <Street>5555 BANDINI BLVD</Street>

      <City>BELL GARDENS</City>

      <State>CA</State>

      <Zip>90201</Zip>

      <IsGuaranteed>1</IsGuaranteed>

    </Location>

  </Commitment>

</ExpressMailCommitmentResponse>


 

 

 

5.0   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].

An error code can be returned for invalid data as well as messages pertaining to given zip codes/ Below is an example for an error that was returned because the service is not guaranteed.

 

<Error>

<Number>-2147219293</Number>

<Source>clsEMCommitments:Respond</Source>

<Description>Priority Mail Express service is available to your supplied destination ZIP Code. However the delivery date cannot be guaranteed.Description>

<HelpFile></HelpFile>

<HelpContext></HelpContext>

</Error>

 

If you need assistance with an error response, contact the Internet Customer Care Center uspstechnicalsupport@mailps.custhelp.com.

 

Powered By OneLink