An error occurred while trying to get USPS order status using the USPS tracking API.
However, when I run the code that I built based on the USPS manual, I get the following error: " 80040B19XML Syntax error: check the XML request to see if it can be parsed. USPSCOM :: DoAuth "
Link to the manual: https://www.usps.com/business/web-tools-apis/track-and-confirm-v1-3a.htm
Here is my code:
$trackingNumber = 123456;
$url = "http://production.shippingapis.com/shippingAPI.dll";
$service = "TrackV2";
$xml = rawurlencode("
<TrackRequest USERID='MYID'>
<TrackID ID=".$trackingNumber."></TrackID>
</TrackRequest>");
$request = $url . "?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);
$result = curl_exec($ch);
curl_close($ch);
$response = new SimpleXMLElement($result);
$deliveryStatus = $response->TrackResponse->TrackInfo->Status;
echo $deliveryStatus;
What am I doing wrong?
source
share