Magento: Using SOAP to get detailed product information

Here a code solution to using the SOAP interface in magento. This example will get all products (and plenty of information about each product).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$time_start = microtime(true);	
try{
	$devClient = new Soapclient('http://192.168.1.61/magento/index.php/api/?wsdl', array('trace'=>1, 'exceptions'=>1));
	$devSession = $devClient->login('apiuser', 'apipassword');
 
	$productList = $devClient->call($devSession, 'catalog_product.list');
	foreach ($productList as $product){
		$theProduct = array();
		$theProduct['product'] = $product;
		$theProduct['attributeSet'] = current($devClient->call($devSession, 'product_attribute_set.list'));
		$theProduct['info'] = $devClient->call($devSession, 'catalog_product.info', $product['sku']);
		$theProduct['related'] = $devClient->call($devSession, 'catalog_product_link.list', array('related', $product['sku']));
		$theProduct['up_sell'] = $devClient->call($devSession, 'catalog_product_link.list', array('up_sell', $product['sku']));
		$theProduct['cross_sell'] = $devClient->call($devSession, 'catalog_product_link.list', array('cross_sell', $product['sku']));
		$theProduct['grouped'] = $devClient->call($devSession, 'catalog_product_link.list', array('grouped', $product['sku']));
		$theProduct['images'] = $devClient->call($devSession, 'catalog_product_attribute_media.list', $product['sku']);
		$theProduct['tierprice'] = $devClient->call($devSession, 'product_tier_price.info', $product['sku']);
		$theProduct['stock'] = $devClient->call($devSession, 'product_stock.list', $product['sku']);
 
		$allProducts[] = $theProduct;
	}
	echo '$allProducts: <pre>' . print_r($allProducts, true) . '</pre>';
 
}
catch (Exception $e){
	echo 'Error on line '. $e->getLine().' in '. $e->getFile() . $e->getMessage();
}
 
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br/><br/>execution time " . $time;

More info on the SOAP API at Magento wiki