tags:

views:

698

answers:

2

If anyone has any experience with the USPS delivery confirmation API, I'd really appreciate any insight I can get...

I am using PHP and cURL to send an XML request to the D.C. API. When I send the response through cURL, I get nothing. No error response, no XML, or anything. When I send the XML through a browser, I get an error response, which is at least a response. I am at a standstill because the error I get through the browser apparantly (according to their support line) means that their server problems are affecting the API. However, I don't know why I wouldn't be able to get that response through cURL.

A: 

My suspicion is that something is off in the structure of your request (e.g., a missing header), since the XML content sounds like it's valid (or at least like USPS's servers read it correctly).

Our implementation of the USPS API uses a raw TCP/IP connection with fsockopen, which has the advantage that I can confirm precisely what we're sending in the structure of the request: POST /ShippingAPI.dll HTTP/1.0

The only headers we're including on the request are these:

User-Agent: (foo)\r\n
Host: (bar)\r\n
Content-Type: text/xml\r\n
Content-Length: strlen($xml)\r\n\r\n

Does that match what you're sending through cURL?

VoteyDisciple
+1  A: 

We're using the Address Validation API and .NET, not Delivery Confirmation and PHP, but maybe I can help.

The XML that you send the post office should just be a party of the query string like this:

https://servername/ShippingAPITest.dll?API=DeliveryConfirmationV3&amp;XML=&lt;DeliveryConfirmationV3.0Request USERID="username">…….</DeliveryConfirmationV3.0Request>

Then they just serve you up an XML document right back. I've never used the cURL library, but maybe you can check that this is what it's actually sending.

Also, have you been approved yet? If not, then they only allow the canned test responses. Anything else will give you an error, even if it would be valid on the production server.

Shea Daniels
I am only using the test server right now, and this is the error I get just trying to get the canned responses back. I have confirmed with USPS support that there is nothing wrong with my account as far as trying to get the test runs to work.
W_P