USPS : API Authorization failure

Exploit picture Exploit · Apr 2, 2012 · Viewed 10.6k times · Source

Why won't the rate work with USPS? I'm using ratev4 and I get an error:

Error:

API Authorization failure. RateV4 is not a valid API name for this protocol.
UspsCom::DoAuth

Here is my code:

<?php
$devurl = "testing.shippingapis.com/ShippingAPITest.dll";
$puburl = "https://secure.shippingapis.com/ShippingAPITest.dll";

$service = "RateV4";
$userid = "690DEVBL1739";

$xml = rawurlencode('<RateV4Request USERID="xxxxx">
    <Revision/>
    <Package ID="1ST">
        <Service>FIRST CLASS</Service>
        <FirstClassMailType>LETTER</FirstClassMailType>
        <ZipOrigination>44106</ZipOrigination>
        <ZipDestination>20770</ZipDestination>
        <Pounds>1</Pounds>
        <Ounces>0.0</Ounces> 
        <Container/>
        <Size>REGULAR</Size> 
        <Machinable>true</Machinable>
    </Package>
    </RateV4Request>');

    $request = $devurl . "?API=" . $service . "&xml=" . $xml;


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



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

    echo "<pre>";
    print_r($response);
    echo "</pre>";

Answer

Manik Arora picture Manik Arora · Jan 16, 2015

I assume that you have already registered for USPS Web Tools here:

https://secure.shippingapis.com/registration/

And have received confirmation from USPS that your account is active:

If you need to set up USPS or your customers are receiving this error on check out (See below) you should confirm the following

Confirm that our USPS API access is approved

Confirm that it is not in test mode and is in production mode
    If USPS says your account is active, this does not mean it is in production mode, - you need to call USPS and specifically request that it be moved to production mode after your account has been approved. A good idea is to perform this quick test:

Insert the following into your browser with your own USERID in place of the XXXX in the URL of any browser:

https://secure.shippingapis.com/ShippingAPITest.dll?API=CarrierPick... USERID="XXXX">ABC Corp.Suite 7771390 Market StreetHoustonTX770581234

If your USPS account is active, it should accept the username.

Confirm that your username and password is for this site only. USPS only allows 1 domain per account.

http://production.shippingapis.com/ShippingAPI.dll

The problem is that by default, you don’t have access to USPS’s production API. They have to approve you first. Keep in mind that they only allow you to use it on one web site per account, so if you’re setting Magento up for a client, customer, or other business entity other than your own you should set up a separate USPS account for them.

That's why you're receiving this text - "Sample Do Not Mail" over the generated shipping label.

You can set up your USPS WebTools account here:

http://www.usps.com/webtools/

Once you have set up your account, they will give you access to the testing environment. The URL for the USPS test API is: http://testing.shippingapis.com/ShippingAPITest.dll

I recommend asking USPS to turn on production mode. When you are approved by USPS for the production API, you should use the following URLs:

http://production.shippingapis.com/ShippingAPI.dll

https://secure.shippingapis.com/ShippingAPI.dll

When you have completed your testing, email the USPS Internet Customer Care Center (ICCC). They will switch your profile to allow you access to the production server and will provide you with the production URLs.

The ICCC is staffed as follows: Monday through Friday from 8:00AM to 8:30PM Eastern Time Saturday from 8:00AM to 6:00PM Eastern Time Sunday and Postal Holidays - Closed except for the following Holidays: Martin Luther King; President's Day; Columbus Day; & Veteran's Day with hours from 9:00AM to 6:00PM Eastern Time

E-mail: [email protected] Telephone: 1-800-344-7779

But remember, it’s very important that you set up a separate USPS account for each web site (or at least one per domain). USPS will disable your access to their production server if you are caught using your account on multiple web sites.

To request access to the USPS production API, fill out the form here: http://www.usps.com/webtools/webtoolsapirequestform.htm

USPS doesn’t allow you to use their API for batch processing or data cleansing, so be sure to NOT check these boxes on the request form.

Once USPS gives you access to their production API server, everything should work corresponding to all USPS shipping options. If you are still having trouble, again check that you have access to USPS’s production API server.