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!
<?php
$request1 = <<< XMLREQUEST
<RateV3Request USERID="XXXXXXXXXXXX">
<Package ID="1ST">
<Service>FIRST CLASS</Service>
<FirstClassMailType>LETTER</FirstClassMailType>
<ZipOrigination>32444</ZipOrigination>
<ZipDestination>90210</ZipDestination>
<Pounds>10</Pounds>
<Ounces>0.75</Ounces>
<Size>REGULAR</Size>
<Machinable>false</Machinable>
</Package>
</RateV3Request>
XMLREQUEST;
$request = "http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV3&XML=" . 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);
curl_close($ch);
print_r($response);
?>