Magento 2 API – Get All Categories
End-to-end Magento integration
Integrate any app or service. Consult our API development experts.
Hello, Magento peeps!
In my last post on Magento 2 API, I provided complete solution to get Magento 2 CMS content through APIs. In case you missed reading it, you can check it out at: Magento 2 API – Get CMS Page Content. In this blog post, I have provided complete tutorial to get categories through Magento 2 REST API.
In case you are developing a third-party application on Magento or integrating another storefront with your Magento 2 admin panel, you may want to display the product categories. Magento 2 provides powerful APIs, making it highly flexible platform eCommerce platform. By default, the platform provides Magento 2 API to get all product categories in the store. I have provided complete guide to Magento 2 API – Get All Categories in this post. And if after saving the category you get an notification of “something went wrong while saving the category” then solve category save error in Magento.
Let’s begin!
How to Get All Categories Using Magento 2 API?
Getting all categories in Magento 2 requires admin access and therefore the client needs to pass admin token along with the API request for authentication. You can read this guide on Magento 2 API – Get Admin Token for more details.
In order to get all categories in Magento 2 through API, we’ll be making a GET request to store_url/categories/ and pass the admin token to authorize the access. Here is how to do it.
Method: GET
URL: store_url/categories/
Authorization Type: Bearer Token
Token: <Admin Token>
Response:
On the authorization of request, Magento returns the list of all active categories in the store through API response.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
{ "items": [ { "id": 3, "parent_id": 2, "name": "Gear", "is_active": true, "position": 4, "level": 2, "children": "4,5,6", "created_at": "2020-11-30 12:22:20", "updated_at": "2020-11-30 12:22:20", "path": "1/2/3", "available_sort_by": [], "include_in_menu": true, "custom_attributes": [ { "attribute_code": "display_mode", "value": "PAGE" }, { "attribute_code": "is_anchor", "value": "0" }, { "attribute_code": "path", "value": "1/2/3" }, { "attribute_code": "children_count", "value": "3" }, { "attribute_code": "url_key", "value": "gear" }, { "attribute_code": "url_path", "value": "gear" } ] }, ], } |
Conclusion
If you are developing a mobile app or third-party application based on Magento, you may require to fetch and display all the categories in the store. You can follow this complete guide to Magento 2 API – get all categories to do that. I hope you will find this guide useful.
In case you still have any doubts or queries regarding Magento 2, feel free to comment. I would be happy to help you. 😇
Do not forget to share this Magento 2 API guide with your developer friends via social media. 😃
Thanks for reading! 🍀
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
2 Comments
I want to get the image attribute as well but it won’t show in this API
rest/V1/categories
Hello Syed,
There is no image option in the response of the above solution as the above does not work for image.
Thank You