Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

API—category.level—doesn’t return the level I’m looking for
 
kwarr
Jr. Member
 
Total Posts:  6
Joined:  2008-12-16
 

I need to retrieve all the child categories under a specific category, and it looks like the API method category.level should do the trick.

However it’s returning only one level, the level under the Root, each time, no matter what params I set up.  I’ve got some test data that has the Root Catalog, a Root Category child and a Gallery child under the Root Category.  3 Categories, 3 levels, one Category per level.

Hopefully someone can spot where I’m going wrong....

Here’s my test code:

$proxy = new SoapClient(’http://myMagentoServer/api/soap/?wsdl’);
$sessionId = $proxy->login(’replicator’, ‘replicator’);

$allCategories = $proxy->call($sessionId, ‘category.tree’); // Get all categories.
print_r($allCategories);

echo “<br>”;
$levelOneCategories = $proxy->call($sessionId, ‘category.level’, array(’base’, ‘default’, 3));
print_r($levelOneCategories);

echo “<br>”;
$levelOneCategories = $proxy->call($sessionId, ‘category.level’, array(null, null, 3));
print_r($levelOneCategories);

Here’s the results:

Array
(
[category_id] => 1
[parent_id] => 0
[name] => Root Catalog
[position] => 1
[level] => 0
[children] => Array
(
[0] => Array
(
[category_id] => 3
[parent_id] => 1
[name] => Root Category
[is_active] => 1
[position] => 2
[level] => 1
[children] => Array
(
[0] => Array
(
[category_id] => 7
[parent_id] => 3
[name] => Galleries
[is_active] => 1
[position] => 1
[level] => 2
[children] => Array
(
)

)

)

)

)

)
<br>Array
(
[0] => Array
(
[category_id] => 3
[parent_id] => 1
[name] => Root Category
[is_active] => 1
[position] => 2
[level] => 1
)

)
<br>Array
(
[0] => Array
(
[category_id] => 3
[parent_id] => 1
[name] => Root Category
[is_active] => 1
[position] => 2
[level] => 1
)

)

 
Magento Community Magento Community
Magento Community
Magento Community
 
pwiz
Jr. Member
 
Total Posts:  1
Joined:  2008-10-28
Italy
 

I know it’s an old thread, but I’ve had the same issue and I think it might be useful to post the solution I found.
The only way to make this method work correctly is passing only the store view code and the parent category id:

$levelOneCategories = $proxy->call($sessionId, ‘category.level’, array(null, ‘default’, 3));

I don’t know if it’s a bug or a lack of documentation.
Bye.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top