Show ALL Customers, Products & Orders API

Posted on: Dec 6, 2011 11:25:07 PM By: Magen Theme

Following on from my prior post: Getting Started with a Magento API, we have now extended a educational to uncover we how to move behind information on Customers, Products and Orders.

After following this educational we should finish adult with a following:

If we have followed a initial educational we should now have an API pivotal etc to enter into a script. You will need an Admin purpose on your web use comment for this to concede we to entrance a lot of data.

Create a record (anywhere) called apilist.php and pulp in a following:

?php

$client = new SoapClient('http://www.yourdomain.co.uk/api/soap/?wsdl');
$session = $client-login('admin', 'admin123'); // bond to a API

$customerlist = $client-call($session, 'customer.list'); // lets get a list of customer
$productlist = $client-call($session, 'product.list'); // lets get a list of products
$orderlist = $client-call($session, 'sales_order.list'); // lets get a list of products

?
div style="width: 400px; float: left; margin: 0 20px;"
h2Customer List/h2
?php /*?pre
?php var_dump($customerlist) // uncover your list  keys for anxiety ?
/pre?php */?
    ul
        ?php foreach($customerlist as $customer): ?
        li(?php relate $customer['customer_id'] ?) - ?php relate $customer['firstname'] ? ?php relate $customer['lastname'] ?/li
        ?php endforeach; ?
    /ul
/div
div style="width: 400px; float: left; margin: 0 20px;"
h2Product List/h2
?php /*?pre
?php var_dump($productlist) // uncover your list  keys for anxiety ?
/pre?php */?
    ul
        ?php foreach($productlist as $product): ?
        li(?php relate $product['sku'] ?) - ?php relate $product['name'] ?/li
        ?php endforeach; ?
    /ul
/div
div style="width: 400px; float: left; margin: 0 20px;"
h2Order List/h2
?php /*?pre
?php var_dump($orderlist) // uncover your list  keys for anxiety ?
/pre?php */?
    ul
        ?php foreach($orderlist as $order): ?
        li(?php relate number_format($order['base_grand_total']) ? ?php relate $order['base_currency_code'] ?) - ?php relate $order['customer_firstname'] ? ?php relate $order['customer_lastname'] ?/li
        ?php endforeach; ?
    /ul
/div

If we have finished all correctly, when we revisit apilist.php in your browser we should see a list of customers, products and orders on your store. we have kept in a var_dump($code) to concede we to perspective all a array keys that we might need to move back.

I wish we have enjoyed this educational – as we can see it’s unequivocally easy to use a Magento API to insert or remove information from Magento.