Magento Core API allows us to retrieve the Orders Placed in a Magento Store. In this example we will be filtering the orders based on its status. Magento Webservices allows us to use Both Soap and XMLRPC for accessing the Core API, for this example i have used both in the below code snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $soapclient = new SoapClient('http://example.com/api/soap/?wsdl'); $sessionId = $soapclient->login('YourAPIUser', 'YourAPIKey'); //Webservice User and API Key // Getting Order listing by Order Status // Example Usage: array('eq' => 'canceled') , array('eq' => 'processing'),array('eq' => 'complete') try { $orders = $soapclient->call($sessionId, 'sales_order.list', array(array('status' => array('eq' => 'pending')))); foreach ($orders as $order) { echo "OrderId:" . $order['order_id'] . " "; } } catch (Exception $fault) { echo $fault->getMessage(); } ?> |
XMLRPC Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php $mageFilename = 'app/Mage.php'; require_once $mageFilename; umask(0); Mage::app(); $xmlrpcclient = new Zend_XMLRPC_Client('http://example.com/api/xmlrpc/'); $session = $xmlrpcclient->call('login', array('YourAPIUser', 'YourAPIKey')); try { $orders = $xmlrpcclient->call('call', array($session, 'sales_order.list', array(array('status' => 'canceled')))); foreach ($orders as $order) { echo "OrderId:" . $order['order_id'] . " "; } } catch (Exception $fault) { echo $fault->getMessage(); } ?> |
Compatability :- Magento 1.4,1.5