Getting Customer Tracking number via SOAP API

by brentwpeterson   Last Updated January 10, 2018 18:09 PM

I have a developer who is saying he can not get the shipmentIncrementId to get the tracking number.

http://devdocs.magento.com/guides/m1x/api/soap/sales/salesOrderShipment/sales_order_shipment.info.html

What is the procedure for getting the tracking number from an order?



Answers 2


This is a silly example with Magento 1.9.2.4

<?php
ini_set('max_execution_time','1000');
set_time_limit(0);

$client = new SoapClient("http://www.yourstore.com/index.php/api/?wsdl");
try {

    //Login
    $session = $client->login("username", "password");

    //Request shipment number 100000001
    $result = $client->call($session, 'sales_order_shipment.info', '100000001');

    //Store shipping information
    $tracking_information = $result['tracks'];

    echo "<pre>";
    //$tracking_infrmation will be an array and can conatin multiple tracking codes. You'll need to iterate the variable and get the number value.
    print_r($tracking_information);
    echo "</pre>";

} catch (SoapFault $exception) {

    echo "There were an error on your request\n\n";
    echo "Code: " . $exception->faultcode . "\n";
    echo "Message: " . $exception->faultstring . "\n";

}
//Logout
$client->endSession($session);
Barbanet
Barbanet
November 04, 2016 15:31 PM

Here is the way to do that with SOAP V1 if you only have the order increment ID:

/** @var array $orderInfo */
$orderInfo = $client->call($session, 'sales_order.info', $orderIncrementId);
/** @var string $orderId */
$orderId = $orderInfo['order_id']; // Entity ID
/** @var array $filters */
$filters = array(
    array('order_id' => array('eq' => $orderId))
);
/** @var array $orderShipments */
$orderShipments = $client->call($session, 'sales_order_shipment.list', $filters);

foreach ($orderShipments as $shipment) {
    /** @var string $shipmentIncrementId */
    $shipmentIncrementId = $shipment['increment_id'];
    /** @var array $shipmentInfo */
    $shipmentInfo = $client->call($session, 'sales_order_shipment.info', $shipmentIncrementId);
    /** @var array $tracks */
    $tracks = $shipmentInfo['tracks'];

    foreach ($tracks as $track) {
        /** @var string $trackingNumber */
        $trackingNumber = $track['track_number'];
    }
}
Coch
Coch
January 10, 2018 18:08 PM

Related Questions


M2 Tracking progress via API

Updated December 03, 2017 08:09 AM

importing and exporting tracking

Updated January 25, 2018 06:09 AM