2

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();
        if(isset($data['categoryId'])){
            $url = $this->baseUrl."rest/V1/categories/".$data['categoryId'];
            $response = $this->curlGet($url,$this->token);
        }else{
            $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).

8

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

  • 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 at 13:02

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.