SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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($chCURLOPT_URL$request);
    curl_setopt($chCURLOPT_HEADERfalse);
    curl_setopt($chCURLOPT_HTTPGETtrue);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_SLL_VERIFYHOSTfalse);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);


    $response curl_exec($ch);
    curl_close($ch); 

    print_r($response);

    ?>
    intragenesis, llc professional web & graphic design

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    intragenesis, llc professional web & graphic design


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •