Pergunta

What message populates when an USPS Exception occurs? The API Name is Tracking & Delivery Information.

I have integrated USPS API successfully on my machine. I am able to get product status with tracking number, but there may be conditions when the exception can occur in API, I want to manage alert for that condition so that I can be informed for that case. I want to know how can I detect the exception?

Foi útil?

Solução 3

I have found result myself

But after lots of research I found the solution for my problem. which is given below:

In USPS "Tracking & Delivery Information" API Integration there are Two Types of XML Request Format that we can send to USPS Server for retrieving the Parcel shipping response by its tracking number in two different way.

1) Track/Confirm Web Tool:- This is intended for display purpose only and in response it returns text messages (summary and detail) only.

API Signature(URL):
http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2   //Live server
Or
http://production.shippingapis.com/ShippingAPITest.dll?API=TrackV2  //Test server

Request Parameters:

<TrackRequest USERID=”xxxxxxxx”>
    <TrackID ID="EJ123456780US"></TrackID>
</TrackRequest>

It returns Response Parameters : summary and detail only

<TrackResponse>
  <TrackInfo ID="E123456780US">
    <TrackSummary>
      Your item was delivered at 6:50 am on February 6 in BARTOW FL 33830.        
    </TrackSummary>
    <TrackDetail>February 6 6:49 am NOTICE LEFT BARTOW FL 33830</TrackDetail>
    <TrackDetail>February 6 6:48 am ARRIVAL AT UNIT BARTOW FL 33830</TrackDetail>
    <TrackDetail>February 6 3:49 am ARRIVAL AT UNIT LAKELAND FL 33805</TrackDetail>
    <TrackDetail>February 5 7:28 pm ENROUTE 33699</TrackDetail>
    <TrackDetail>February 5 7:18 pm ACCEPT OR PICKUP 33699</TrackDetail>
  </TrackInfo>
</TrackResponse>

2) Track/Confirm Fields Web Tool:- This is the request format that worked for me, I tested this by implementing this. This request returns full information of a parcel tracking number like:- API Signature(URL):Same as used for first one

Request Example:

<TrackFieldRequest USERID=" xxxxxxxx">
 <TrackID ID="01805213907042762274"></TrackID>
</TrackFieldRequest>

Response Example:

<TrackResponse>
    <TrackInfo ID="01805213907042762274">
        <TrackSummary>
            <EventTime>12:12 pm</EventTime>
            <EventDate>May 21, 2001</EventDate>
            <Event>DELIVERED</Event>
            <EventCity>NEWTON</EventCity>
            <EventState>IA</EventState>
            <EventZIPCode>50208</EventZIPCode>
            <EventCountry/>
            <FirmName></FirmName>
            <Name></Name>
            <AuthorizedAgent></AuthorizedAgent>
        </TrackSummary>
        <TrackDetail>
            <EventTime>9:24 pm</EventTime>
            <EventDate>March 28, 2001</EventDate>
            <Event>ENROUTE</Event>
            <EventCity>DES MOINES</EventCity>
            <EventState>IA</EventState>
            <EventZIPCode>50395</EventZIPCode>
            <EventCountry/>
            <FirmName/>
            <Name/>
            <AuthorizedAgent/>
        </TrackDetail>
    .
    .
    .
</TrackResponse>

Note:I have Converted this XML response into simple PHP Array and used the "Event" filed for managing alert for all conditions Like ENROUTE/DELIVERED etc.. And manage error/exception that occurs by its error id which returns in its response array.

See for More details

Outras dicas

I've used the EasyPost API to get more detailed tracking and delivery information? That might be helpful? I found the USPS exception notifications not super useful.

Otherwise, you could set up an exception notification service to alert you when API exceptions occur.

I've noticed there's another form of this API, where you get a lot more information in the response. Pass this XML document in the "XML" query string parameter:

<TrackFieldRequest USERID="XXXXXXXX">
  <Revision>1</Revision>
  <ClientIp>x.x.x.x</ClientIp>
  <SourceId>customer / company name</SourceId>
  <TrackID ID="9102xxxxxxxxx"></TrackID>
</TrackFieldRequest>

And the response with this XML document looks like:

<TrackResponse>
  <TrackInfo ID="9102xxxxxx">
    <Class>Priority Mail 3-Day<SUP>&#153;</SUP></Class>
    <ClassOfMailCode>PM</ClassOfMailCode>
    <DestinationCity>TOMAHAWK</DestinationCity>
    <DestinationState>WI</DestinationState>
    <DestinationZip>54487</DestinationZip>
    <EmailEnabled>true</EmailEnabled>
    <ExpectedDeliveryDate>March 4, 2014</ExpectedDeliveryDate>
    <KahalaIndicator>false</KahalaIndicator>
    <MailTypeCode>DM</MailTypeCode>
    <MPDATE>2014-03-01 20:19:24.000000</MPDATE>
    <MPSUFFIX>121219566</MPSUFFIX>
    <OriginCity>EAST FALMOUTH</OriginCity>
    <OriginState>MA</OriginState>
    <OriginZip>02536</OriginZip>
    <PodEnabled>false</PodEnabled>
    <RestoreEnabled>false</RestoreEnabled>
    <RreEnabled>false</RreEnabled>
    <Service>$50 insurance included</Service>
    <Service>USPS Tracking<SUP>&#153;</SUP></Service>
    <ServiceTypeCode>055</ServiceTypeCode>
    <Status>Processed at USPS Origin Sort Facility</Status>
    <StatusCategory>In Transit</StatusCategory>
    <StatusSummary>Your item has been processed at the origin sort facility at 11:45 pm on March 1, 2014 in NASHUA, NH 03063.</StatusSummary>
    <TABLECODE>T</TABLECODE>
    <TrackSummary>
      <EventTime>11:45 pm</EventTime>
      <EventDate>March 1, 2014</EventDate>
      <Event>Processed at USPS Origin Sort Facility</Event>
      <EventCity>NASHUA</EventCity>
      <EventState>NH</EventState>
      <EventZIPCode>03063</EventZIPCode>
      <EventCountry/>
      <FirmName/><Name/><AuthorizedAgent>false</AuthorizedAgent>
      <EventCode>10</EventCode>
    </TrackSummary>
    <TrackDetail>
      <EventTime/>
      <EventDate>March 1, 2014</EventDate>
      <Event>Electronic Shipping Info Received</Event>
. . .
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top