1

I'm new to Magento I try to call category level using Magento SOAP API with parent category id. I use following code.

<?php
$proxy = new SoapClient('http://domain/index.php/api/soap/?wsdl');
$session = $proxy->login('user', 'password');
$result = $proxy->call($session,'catalog_category.level');
echo json_encode($result);
?>

Here for the above code, "Default Category" details are coming. now I try to call some other category by using following codes.

$result = $proxy->call($session,'catalog_category.level',12);

That is not working

$arguments = array( 'parentCategory' => 12);
$result = $proxy->call($session,'catalog_category.level',$arguments);

This is also not working.

Then I try to call category tree using following code.

 <?php
$proxy = new SoapClient('http://domain/index.php/api/soap/?wsdl');
$session = $proxy->login('user', 'password');
$result = $proxy->call($session,'catalog_category.tree');
echo json_encode($result);
?>

it showing all the category tree. it means API is working but whenever I try to pass an argument it showing server not found an error.

Can any one please tell me how to pass arguments with the request.

3
  • check API Example Here Oct 19, 2015 at 6:51
  • That example is without parameter. anyway thanks for trying to help me :)
    – Arul James
    Oct 19, 2015 at 6:54
  • you can check parameter there in doc Oct 19, 2015 at 7:01

3 Answers 3

1
<?php
/* code to check SOAP enabled in your server or not */
echo (extension_loaded('soap'))?'SOAP Enabled':'SOAP Disabled';echo '<br />';
echo (class_exists('SOAPClient'))?'SOAP Client Present':'SOAP Client Absent';echo '<br />';
echo (class_exists('SOAPServer'))?'SOAP Server Present':'SOAP Server Absent';echo '<br />';



/** Code to authenticate SOAP credentials and authorize the request URL **/
$apiUrl = 'http://localhost/magento/index.php/api/soap/?wsdl';
$apiUser = 'yourSoapApiUser'; 
$apiKey = 'yourSoapApiKey';

ini_set("soap.wsdl_cache_enabled", "0");
try{
    $client = new SoapClient($apiUrl, array('cache_wsdl' => WSDL_CACHE_NONE));
} catch (SoapFault  $e) {
    echo 'Error in Soap Connection : '.$e->getMessage();
}
try {
    $session = $client->login($apiUser, $apiKey);
    if($session){
        $params = array('storeId'=>$storeId,'categoryId'=>$categoryId);
        try {
            $result = $client->call($session, 'catalog_category.tree',$params);
            echo json_encode($result);
        } catch(Exception $e) {
            $result = json_encode(array('isFault' => 1, 'faultMessage'=>$e->getMessage()));
            $error = true;
        }
    }else echo 'SOAP Connection Failed.';
} catch (SoapFault  $e) {
    echo 'Wrong Soap credentials : '.$e->getMessage();
}

The above code worked fine for me. If it won't for you then check your corresponding Api.php method.

Gist : Multiple request params are always sent in an array.

0

You will need to call it like

$proxy->call($sessionId, 'category.level', array(null, null, 12));

For more information about the function check class

Mage_Catalog_Model_Category_Api and function `level($website = null, $store = null, $categoryId = null)`

If you want to pass particular website and store you can pass it instead of null parameter.

1
  • it is not working brother
    – Arul James
    Oct 19, 2015 at 8:44
0

i manage to get output using soapv2. but it is slow compare to soapv1 but it is giving the required out put. the code i use to pass parameter is given as below.

 <?php
$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$session = $proxy->login((object)array('username' => 'user', 'apiKey' => 'password'));
$result = $proxy->catalogCategoryTree((object)array('sessionId' => $session->result, 'parentId' => '12'));
echo json_encode($result);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.