Magento – Delete Products using SOAP API

A question was posted in the comments section regarding deleting every product in the Magento Catalog without manually removing them via the Magento admin, so I wrote up a quick script using the Magento SOAP API. It’s not the fastest method, and if you’d like to see a quicker way using the Mage class, see this post here – Magento: Delete Products Programmatically.

On to the good stuff! By using the Magento SOAP API, we can easily expand upon this simple script, and we have somewhat “future-proofed” ourselves by doing it this way as well. The downfall is the speed at which the script executes, but the upside is that we can execute it anytime.

*Disclaimer: there are a few pitfalls in my script, as I am not checking to see if this is a secure area of the site (as in logged in, password-protected), so anyone with the knowledge of the script’s path can execute it and delete your products! So make sure if you use or build upon this, you know what you’re doing and BACKUP!

The file: removeProds.php

		$proxy = new SoapClient('', array('trace' => 1, 'connection_timeout' => 120)); 
		$sessionId = $proxy->login("testApiUser", "testApiPass"); 
		$products = $proxy->call($sessionId, 'product.list'); 
		foreach($products as $product)
			if($proxy->call($sessionId, 'product.delete', $product['sku']))
				echo "Product deleted successfully with ID: " . $product['product_id'] . " and name: ". $product['name'] ."<br />";
	catch (Exception $e) 

Make sure you change your SoapClient path to your correct domain, as well as create an API user in your Magento admin.

I’ve tested this on my machine a few times and have been successfully every single time. This will remove ALL products – it will not reset the product IDs.

Posted in Magento, Magento Enterprise, Magento Fixes, Magento Professional, PHP