2

I am using cURL to submit POST information to the usps shipping rate calculator.

$info = "<?xml version='1.0' encoding='UTF-8'?>
<RateV4Request USERID='xxxx'>
    <Package ID='$aucid'>
        <Service>Priority</Service>
        <ZipOrigination>xxxx</ZipOrigination>
        <ZipDestination>$zip</ZipDestination>
        <Size>$size</Size>
        <Pounds>$pounds</Pounds>
        <Ounces>$ounces</Ounces>
        <Container>RECTANGULAR</Container>
        <Width>$width</Width>
        <Length>$length</Length>
        <Height>$height</Height>
        <SpecialServices><SpecialService>108</SpecialService></SpecialServices>
    </Package>
</RateV4Request>";

$array = array("API" => "RateV4", "XML" => $info);

$link = "http://production.shippingapis.com/ShippingAPI.dll";

curl_setopt($ch, CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$array);
$answer=curl_exec($ch);
echo $answer;
curl_close($ch);

When I signed up for the USPS web tools, an email was sent with the USERID (I have replaced it with xs due to its sensitive nature).

In that same email, it was specified that Rate Calculation was allowed. Here's the error that is returned:

80040B19XML Syntax Error:
Please check the XML request to see if it can be parsed.USPSCOM::DoAuth

I went ahead and took the XML that is echoed and plugged it into an xmlvalidation.com and it found no errors. I have also tried it without <?xml version="1.0" encoding="UTF-8"> line at the top.

1 Answers1

2

PHP is turning the Package ID into scientific notation because it's just a big "number", so you need to stop that from happening by making it a string.

Instead of this: <Package ID='$aucid'>

Try this: <Package ID=\"".$aucid."\">

You may also need to wrap that entire XML in rawurlencode

jonmrich
  • 4,233
  • 5
  • 42
  • 94