USPS Rate API & PHP / Curl - Help?

I’ve been working on using PHP with Curl to call various USPS api’s…maybe someone that has done this can give me some pointers?

First, I started simple and set up a request to call the tracking api (TrackV2) and the results come back fine. I had to use rawurlencode(), otherwise, curl wouldn’t pass the XML variable correctly.

However, when I try to call the RateV3 api, I get the following message :

" 80040b1a API Authorization failure. RateV3 is not a valid API name for this protocol. UspsCom::DoAuth"

Here is my php code (of course I replaced the USERID field with dummy information )…maybe someone here on sitepoint that has successfully used the RateV3 api can offer some help / advice.

Thanks - and my cramped brain thanks you!


$request1 = <<< XMLREQUEST
    <Package ID="1ST">
      <Service>FIRST CLASS</Service>

$request = "" . rawurlencode($request1);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SLL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($ch);



Thanks everyone that viewed the thread. I found the solution…maybe someone in the same situation may find this of use :

RateV2 will still work with the test server – however, the structure of the xml request is different since it doesn’t allow for length, width or height.

RateV3 will only work on the production server, not the test server. So, anyone reading that had the same problem, take the code above, change the USERID in the XML request to your user id provided by USPS, then change the http:// address to the address of the production server.