Create partial shipement using Magento API

We know how to create shipment order from Magneto API from API documentation but how to create shipment order partially and add tracking to it through magento api ?

Lets do this. Here $itemsArray is most important as it contains order item id and its quantity.

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');

$sessionId = $proxy->login('apiUser', 'apiKey');

$notShipedOrderId  = '100000003';

// Prepare items array for partial shipment

$itemsArray=array('order_item_id' => '13', 'qty' => '1');

// Create new shipment

$newShipmentId = $proxy->call($sessionId, 'sales_order_shipment.create', array($notShipedOrderId, $itemsArray, 'Shipment Created', true, true));

// View new shipment

$shipment = $proxy->call($sessionId, '', $newShipmentId);

// Get allowed carriers for shipping

$allowedCarriers = $proxy->call($sessionId, 'sales_order_shipment.getCarriers', $notShipedOrderId);
$choosenCarrier = key($allowedCarriers);

// Add tracking

$newTrackId = $proxy->call($sessionId, 'sales_order_shipment.addTrack', array($newShipmentId, $choosenCarrier, 'My Track', rand(5000, 9000)));
$shipment = $proxy->call($sessionId, '', $newShipmentId);

after executing the code you will see that partial shipment has been created in Magento. You can use the item array with the same format to create partial invoices.

You can check create() method in “Mage_Sales_Model_Order_Shipment_Api_V2 “ and “Mage_Sales_Model_Order_Invoice_Api_V2” for more details.