magento soap api check product exist or not

In magento there is soap and xml rpc api  catalog_product.info which will retrive product based on SKU or Product ID.But which will only works well when there is poduct available otherwise it will generate exception. So how to check if product is exist or not Bellow given code works when the product is exist or not.

   
        $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
        $sessionId = $proxy->login('apiUser', 'apiKey');
        $product_exist=null;


        try{

          $product_exist=$proxy->call($sessionId, 'product.info',
           array('sku_of_product or product id'));
          }
          catch(exception $e){
          //nothing to do
         }
      
        if($product_exist==null or  $product_exist==""){
           echo "product is not exist"
        }
        else {
           echo "product is exist"
        }

inner try catch block not allow magento exception and code will countnue from next step.

Leave a Reply

Your email address will not be published. Required fields are marked *