Home  |  About  | Last |  Submit  |  Contact
AllQuests.com



Previous Question:  get contents from http request  PHPNext Question:  mail function  PHP
Question USPS Rate API PHP Curl Help ( SitePoint Forums PHP )
Updated: 2008-09-17 16:00:02 (1)
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:oAuth"

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 Code:

<?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);

?>

Answers: USPS Rate API PHP Curl Help ( SitePoint Forums PHP )
USPS Rate API PHP Curl Help

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.

holmescreek

Previous Question:  get contents from http request  SitePoint Forums  PHPNext Question:  mail function  SitePoint Forums  PHP

- Source: USPS Rate API PHP Curl Help SitePoint Forums PHP
- Previous Question: get contents from http request SitePoint Forums PHP
- Next Question: mail function SitePoint Forums PHP