I am using "rest/V1/categories/" (Magento 2 Rest API). In documentation(devdocs.magento.com/swagger/#) it says "Retrieve list of categories" but it only returns default category(and its all children) every time. How can i get the list of all categories(those which are parent including default) enter image description here

This is how i am doing it,

public function getCatagory($data){
        $response = array();
            $url = $this->baseUrl."rest/V1/categories/".$data['categoryId'];
            $response = $this->curlGet($url,$this->token);
            $url = $this->baseUrl."rest/V1/categories/";
            $response = $this->curlGet($url,$this->token);
        return $response;

I am executing else part here "rest/V1/categories/" and i am getting,

  "id": 2,
  "parent_id": 1,
  "name": "Default Category",
  "is_active": true,
  "position": 1,
  "level": 1,
  "product_count": 0,
  "children_data": [


It only giving me default why are the other categories missing as shown in the attached image of admin panel. Please help!! Thanks i advance(I don't want to put all my categories under default as children, i know its a way out, but i have already made each of them a parent as they are shown in the images attached now i just want to fetch them).


Well you can easily get all your categories by passing "all" keyword in your categories get API URL

It will give you all the categories including all your root categories.

Try below Steps:

Note : Make sure you pass all keyword in Url and it will works

| improve this answer | |
  • Well that works perfectly fine!! Can you please share with me the reference to the Magento documentation regarding the use of this "all" keyword? I couldn't find anything here devdocs.magento.com/swagger – Abdul Moiz Jun 29 '17 at 13:57
  • 1
    @AbdulMoiz Happy to help :) ,actually there is no documentation for that , i have gone through rest api controller and its interface and find this kind of url . you can refer core module for that – Manthan Dave Jun 30 '17 at 4:36
  • @ManthanDave thanks for the help. However, I need to get the category structure only for the website in which user is in? Can I do that? – Butterfly Jun 24 '19 at 13:02

For Magento 2.3.3 version its not giving the name in the response. { "id": 1, "parent_id": 0, "name": null, "is_active": null, "position": 0, "level": 0, "product_count": null, "children_data": [ { "id": 2, "parent_id": 1, "name": null, "is_active": null, "position": 1, "level": 1, "product_count": null, "children_data": [] } ] }

| improve this answer | |

This will help you get the category name. It works for me Data

public function getTree($node, $depth = null, $currentLevel = 0)
    /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface[] $children */
    // $children = $this->getChildren($node, $depth, $currentLevel);
    // /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface $tree */
    // $tree = $this->treeFactory->create();
    // $tree->setId($node->getId())
    //     ->setParentId($node->getParentId())
    //     ->setName($node->getName())
    //     ->setPosition($node->getPosition())
    //     ->setLevel($node->getLevel())
    //     ->setIsActive($node->getIsActive())
    //     ->setProductCount($node->getProductCount())
    //     ->setChildrenData($children);
    // return $tree;

   $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
   $categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
   $categoryId = $node->getId();
   $nodeS = $categoryFactory->create()->load($categoryId);
   /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface[] $children */
   $children = $this->getChildren($node, $depth, $currentLevel);
   /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface $tree */
   $tree = $this->treeFactory->create();
   return $tree;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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