header

Magento 1.x Software Support Notice

For Magento Commerce 1, Magento is providing software support through June 2020. Depending on your Magento Commerce 1 version, software support may include both quality fixes and security patches. Please review our Magento Software Lifecycle Policy to see how your version of Magento Commerce 1 is supported.

For Magento Open Source 1.5 to 1.9, Magento is providing software security patches through June 2020 to ensure those sites remain secure and compliant. Visit our information page for more details about our software maintenance policy and other considerations for your business.

Category Tree

Module: Mage_Catalog

The Mage_Catalog module allows you to manage categories and products.

Resource Name: catalog_category

Aliases:

Method:

Allows you to retrieve the hierarchical tree of categories.

Aliases:

Arguments:

Type Name Description
string sessionId Session ID
string parentId ID of the parent category (optional)
string storeView Store view (optional)

Returns:

Type Name Description
array tree Array of catalogCategoryTree

The catalogCategoryTree content is as follows:

Type Name Description
int category_id Category ID
int parent_id
Parent category ID
string name
Category name
int position
Category position
int level
Category level
array children
Array of CatalogCategoryEntities

The catalogCategoryEntity content is as follows:

Type Name Description
int category_id
Category ID
int parent_id
Parent category ID
string name
Category name
int is_active
defines whether the category is active
int position
Category position
int level
Category level
array children
Array of CatalogCategoryEntities

Examples

Request Example SOAP V1
$client = new SoapClient('http://magentohost/api/soap/?wsdl');

// If somestuff requires API authentication,
// then get a session token
$session = $client->login('apiUser', 'apiKey');

$result = $client->call($session, 'catalog_category.tree');
var_dump($result);

// If you don't need the session anymore
//$client->endSession($session);
Request Example SOAP V2
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary

$result = $proxy->catalogCategoryTree($sessionId);
var_dump($result);
Request Example SOAP V2 (WS-I Compliance Mode)
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey'));

$result = $proxy->catalogCategoryTree((object)array('sessionId' => $sessionId->result, 'parentId' => '15'));
var_dump($result->result);
Response Example SOAP V1
array
  'category_id' => string '1' (length=1)
  'parent_id' => string '0' (length=1)
  'name' => string 'Root Catalog' (length=12)
  'is_active' => null
  'position' => string '0' (length=1)
  'level' => string '0' (length=1)
  'children' =>
    array
      0 =>
        array
          'category_id' => string '2' (length=1)
          'parent_id' => string '1' (length=1)
          'name' => string 'Default Category' (length=16)
          'is_active' => string '1' (length=1)
          'position' => string '1' (length=1)
          'level' => string '1' (length=1)
          'children' =>
            array
              ...
      1 =>
        array
          'category_id' => string '3' (length=1)
          'parent_id' => string '1' (length=1)
          'name' => string 'root_category' (length=13)
          'is_active' => string '1' (length=1)
          'position' => string '2' (length=1)
          'level' => string '1' (length=1)
          'children' =>
            array
              ...