Working with the USPS Shipping API is not fun. The fact that it requires at least one (1) phone call to USPS Internet Customer Care Center (ICCC) to get activated is a show-stopper in my opinion. If you aren’t in a hurry to get anything done today, you can email for activation instead of calling.

A long time client of mine is using OpenCart, which is a favorite open source shopping cart. He acquired a USPS shipping label module that needed to be installed to make his life easier. Not sure if he had to pay for the module or not, but it needed a little tweaking before it would work properly…


Before I can even use the module, I need a User ID to use the USPS shipping API. Keep in mind this is DIFFERENT than the username to log into the USPS webtools. I go to the USPS Shipping API Registration page and create an account. I received an email with a User ID and Password to use with their API system (in addition to some API URLs to use for your XML communication). This is when I have to make the call to ICCC.

Surprisingly, when I called, it only took about 3 minutes from start to finish. The support tech asked a few simple questions and had my UserID enabled. After a simple test, I verified that I was able to connect to their production server.

NOTE: Don’t be surprised if you need to make more than one (1) phone call as I needed to so I could enable DeliveryConfirmationV3 for printing labels.

USPS Internet Customer Care Center (ICCC):

  • (800) 344-7779
  • 7AM – 11PM Eastern Time

 

Now that I can connect to the USPS production server, I am ready to test. Lucky for me I have a lot of live data to test with. Lets do some tests!


https://secure.shippingapis.com/ShippingAPI.dll?API=DeliveryConfirmationV3&XML=<DeliveryConfirmationV3.0Request USERID="123XXXXX4567">
<Option>1</Option>
<ImageParameters />
<FromName>Herman Munster</FromName>
<FromFirm />
<FromAddress1>1313 Mockingbird Ln</FromAddress1>
<FromAddress2></FromAddress2>
<FromCity>Scaryville</FromCity>
<FromState>3624</FromState>
<FromZip5>91913</FromZip5>
<FromZip4></FromZip4>
<ToName>Homer Simpson</ToName>
<ToFirm></ToFirm>
<ToAddress1>742 Evergreen Terrace</ToAddress1>
<ToAddress2></ToAddress2>
<ToCity>Springfield</ToCity>
<ToState>State</ToState>
<ToZip5>90210</ToZip5>
<ToZip4></ToZip4>
<WeightInOunces>32</WeightInOunces>
<ServiceType>Priority</ServiceType>
<POZipCode></POZipCode>
<ImageType>PDF</ImageType>
<LabelDate></LabelDate>
<CustomerRefNo></CustomerRefNo>
<AddressServiceRequested>False</AddressServiceRequested>
<SenderName></SenderName>
<SenderEMail></SenderEMail>
<RecipientName></RecipientName>
<RecipientEMail></RecipientEMail>
</DeliveryConfirmationV3.0Request>

* The XML above is using fictitious data.

When I send the above XML to the USPS Shipping API, I receive the following response:


<?xml version="1.0"?>
<Error><Number>-2147219078</Number><Source>DC_Respond.;SOLServerConfrm.DC_Respond</Source><Description>XML Missing From Address</Description><HelpFile></HelpFile><HelpContext>1000440</HelpContext></Error></code>

Missing From Address? I have a from address! WTF? I guess I needed to do a little more RTFM. To my discovery, <FromAddress1> should be the SECOND line of the address (IE. Suite 2B, Apt 3, Unit 12) and <FromAddress2> should be the FIRST line of the address (IE. 1313 Mockingbird Ln, 1060 W Addison) and is a required field of at least 1 character. Before you get too excited, you will need to do the same for <ToAddress1> and <ToAddress2>.

Ok, let me make a few changes and try again…


https://secure.shippingapis.com/ShippingAPI.dll?API=DeliveryConfirmationV3&XML=<DeliveryConfirmationV3.0Request USERID="123XXXXX4567">
<Option>1</Option>
<ImageParameters />
<FromName>Herman Munster</FromName>
<FromFirm />
<FromAddress1></FromAddress2>
<FromAddress2>1313 Mockingbird Ln</FromAddress2>
<FromCity>Scaryville</FromCity>
<FromState>3624</FromState>
<FromZip5>91913</FromZip5>
<FromZip4></FromZip4>
<ToName>Homer Simpson</ToName>
<ToFirm></ToFirm>
<ToAddress1></ToAddress1>
<ToAddress2>742 Evergreen Terrace</ToAddress2>
<ToCity>Springfield</ToCity>
<ToState>State</ToState>
<ToZip5>90210</ToZip5>
<ToZip4></ToZip4>
<WeightInOunces>32</WeightInOunces>
<ServiceType>Priority</ServiceType>
<POZipCode></POZipCode>
<ImageType>PDF</ImageType>
<LabelDate></LabelDate>
<CustomerRefNo></CustomerRefNo>
<AddressServiceRequested>False</AddressServiceRequested>
<SenderName></SenderName>
<SenderEMail></SenderEMail>
<RecipientName></RecipientName>
<RecipientEMail></RecipientEMail>
</DeliveryConfirmationV3.0Request>

Survey says?!….

<?xml version=”1.0″?>
<DeliveryConfirmationV3.0Response><DeliveryConfirmationNumber>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</DeliveryConfirmationNumber><DeliveryConfirmationLabel>JVBERi0xLjI…………..</DeliveryConfirmationLabel><ToName>Homer Simpson</ToName><ToFirm></ToFirm><ToAddress1></ToAddress1><ToAddress2>742 EVERGREEN TERRACE</ToAddress2><ToCity>SPRINGFIELD</ToCity><ToState>XX</ToState><ToZip5>90210</ToZip5><ToZip4>XXXX</ToZip4><Postnet>90210XXXX</Postnet></DeliveryConfirmationV3.0Response>

B-E-A utiful! Finally it works.

Remember to test, test, test. I found that using a pound symbol (#) in an address when referencing an apartment, is bad. You can change the pound sign (#) to the word "UNIT" in your XML.

Using the USPS XML APIs are probably a never-ending battle. But the more you work at it the better/easier it will get.


Comments