2

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?

2 Answers 2

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);
4
  • I am assuming this is the Shipping increment id and not the order increment id? Commented Nov 7, 2016 at 14:51
  • Yes, the Shipment ID. Which information do you have for this request? Can you explain a little bit more the workflow for your API request?
    – Barbanet
    Commented Nov 7, 2016 at 21:50
  • All they have is the Increment Id from the order, they don't have the shipping id. Commented Nov 8, 2016 at 0:02
  • There isn't an easy way to do that in that case. If that's the only information that you have you'll need to store in your side some information from Orders and Shipment to match both values. Is it possible to know, in some way, if an Order has shipment because you can check inside the 'status_history' of an order if there's a shipment. But that's all the information that you'll get from an Order.
    – Barbanet
    Commented Nov 10, 2016 at 3:07
1

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'];
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.