Reputation: 2018
I've got different shipments and some of them contain more then one package. I've created this request:
$data ="<?xml version=\"1.0\"?>
<AccessRequest xml:lang='en-US'>
<AccessLicenseNumber>myLicenceNumber</AccessLicenseNumber>
<UserId>myUserId</UserId>
<Password>myPass</Password>
</AccessRequest>
<?xml version=\"1.0\"?>
<TrackRequest>
<Request>
<TransactionReference>
<CustomerContext>
<InternalKey>hello</InternalKey>
</CustomerContext>
<XpciVersion>1.0</XpciVersion>
</TransactionReference>
<RequestAction>Track</RequestAction>
</Request>
<TrackingNumber>myTrackingNumber</TrackingNumber>
</TrackRequest>";
$ch = curl_init("https://www.ups.com/ups.app/xml/Track");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result=curl_exec ($ch);
$data = strstr($result, '<?');
$xml=simplexml_load_string($data);
print_r($xml);
It returns a lot of valuable information, but it doesn't return number of packages if there is more than one. How can I get this information, which is called "Multiple Packages"? Thank you.
Upvotes: 0
Views: 1253
Reputation: 2018
I needed a quick solution so I decided to add this to my method:
$tracking_url = 'http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums='.$trackingNumber;
$html = file_get_html($tracking_url);
foreach($html->find('.module1 dd') as $e) {
if(is_numeric($e->innertext)) {
$number_of_packages = $e->innertext;
}
}
This example uses simple_php_dom.php class.
Upvotes: 0
Reputation: 332
You could try setting up webhooks with something like EasyPost? You can see what package variables the USPS requires here - https://www.easypost.com/docs/api#parcels
Otherwise, for more help can you show me what this call is returning?
Upvotes: 1