USPS Web Tools

USPS Web Tools

I was trying to add the USPS API into osCommerce. I received the following error when adding this shipping module:

RateV3 is not a valid API name for this protocol

This is because when you create an account for the Web Tools at USPS you only have access to their test server. The USPS test server can only use RateV2, so test using this code below, then request to be switched to use the production server. Then you can use RateV3 on the production server and the USPS module for osCommerce will work.

<?php

$request1 = <<< XMLREQUEST
<RateV2Request USERID="xxxxxxxxxxxxx">
<Package ID="0">
<Service>PRIORITY</Service>
<ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination>
<Pounds>10</Pounds>
<Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size>
</Package>
</RateV2Request>
XMLREQUEST;


$request = "http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&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);

echo($response);

?>

2 thoughts on “USPS Web Tools

  1. Pingback: Usps Tools

  2. Pingback: Usps Api

Leave a Reply