Jump to content

USPS tracking info


123guy

Recommended Posts

I am trying to integrate USPS Tracking info into my website. I have obtained a web tools user id from them...but I need to know how I send the request to the server and back to the site via php. Can any one help me out with this by providing some code, or by posting a good link to get me started? thanks

Link to comment
Share on other sites

yes I have, the issue is, I don't know how I call the server. I am getting very confused on how you use the url they gave you. I found this code here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<?php
//enter your username and password
$data_string ='API=TrackV2&XML=<TrackRequest USERID="xxx"><TrackID ID="EJ958088694US"></TrackID></TrackRequest>';
// Get a CURL handle


// Tell CURL the URL of the recipient script
$curl_handle = curl_init ();
curl_setopt ($curl_handle, CURLOPT_URL, 'http://testing.shippingapis.com/ShippingAPITest.dll');
// This section sets various options. See http://www.php.net/manual/en/function.curl-setopt.php
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);
// Perform the POST and get the data returned by the server.
$result = curl_exec ($curl_handle) or die ("There has been a CURL_EXEC error");
// Close the CURL handle
curl_close ($curl_handle);
echo $result;
?>


</head>


<body>


</body>
</html>

but on this everything displays on the same line. Maybe this one will work, but I need it to display correctly. it looks like this right now

 

Your item was delivered at 1:39 pm on June 1 in WOBURN MA 01815.May 30 7:44 am NOTICE LEFT WOBURN MA 01815.May 30 7:36 am ARRIVAL AT UNIT NORTH READING MA 01889.May 29 6:00 pm ACCEPT OR PICKUP PORTSMOUTH NH 03801.

Link to comment
Share on other sites

It probably gives you back an XML document with the information.  Change your code to:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>

<?php
//enter your username and password
$data_string ='API=TrackV2&XML=<TrackRequest USERID="xxx"><TrackID ID="EJ958088694US"></TrackID></TrackRequest>';

// Get a CURL handle
// Tell CURL the URL of the recipient script
$curl_handle = curl_init ();
curl_setopt ($curl_handle, CURLOPT_URL, 'http://testing.shippingapis.com/ShippingAPITest.dll');
// This section sets various options. See http://www.php.net/manual/en/function.curl-setopt.php
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);
// Perform the POST and get the data returned by the server.
$result = curl_exec ($curl_handle) or die ("There has been a CURL_EXEC error");
// Close the CURL handle
curl_close ($curl_handle);
echo htmlentities($result);
?>
</body>
</html>

 

That will let you see any XML tags the output may contain.  If it is an XML document, you'll need to use something like SimpleXML or DOMDocument to parse it and extract the information you want, then output it in whatever format you want.

 

Link to comment
Share on other sites

it still displays all in one line with no breaks.

<TrackResponse><TrackInfo ID="EJ958088694US"><TrackSummary>Your item was delivered at 1:39 pm on June 1 in WOBURN MA 01815.</TrackSummary><TrackDetail>May 30 7:44 am NOTICE LEFT WOBURN MA 01815.</TrackDetail><TrackDetail>May 30 7:36 am ARRIVAL AT UNIT NORTH READING MA 01889.</TrackDetail><TrackDetail>May 29 6:00 pm ACCEPT OR PICKUP PORTSMOUTH NH 03801.</TrackDetail></TrackInfo></TrackResponse>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.