{"id":2550,"date":"2024-12-31T20:22:45","date_gmt":"2024-12-31T20:22:45","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/magento-2-api-get-all-categories\/"},"modified":"2025-04-24T09:39:19","modified_gmt":"2025-04-24T04:09:19","slug":"magento-2-api-get-all-categories","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-api-get-all-categories\/","title":{"rendered":"Magento 2 API &#8211; Get All Categories"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello, Magento peeps!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my last post on&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API<\/a>, I provided complete solution to get Magento 2 CMS content through APIs. In case you missed reading it, you can check it out at:&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-cms-page-content\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API \u2013 Get CMS Page Content<\/a>. In this blog post, I have provided complete tutorial to get categories through Magento 2 REST API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&nbsp;<em><strong>Magento 2 API \u2013 Get All Categories&nbsp;<\/strong><\/em>in this post. And if after saving the category you get an notification of \u201csomething went wrong while saving the category\u201d then&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/category-save-error-in-magento\/\">solve category save error in Magento<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s begin!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Get All Categories Using Magento 2 API?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Getting all&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/how-to-solve-category-move-error-in-magento-2\/\">categories in Magento 2<\/a>&nbsp;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&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-admin-token\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API \u2013 Get Admin Token<\/a>&nbsp;for more details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to get all categories in Magento 2 through API, we\u2019ll be making a GET request to&nbsp;<em>store_url\/categories\/<\/em>&nbsp;and pass the admin token to authorize the access. Here is how to do it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>GET<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>URL:&nbsp;<\/strong><em>store_url\/categories\/<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Authorization Type:&nbsp;<\/strong>Bearer Token<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Token:&nbsp;<\/strong>&lt;Admin Token&gt;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/05\/Magento-2-API-Get-All-Categories-700x404-1.png\" alt=\"Magento 2 API Get All Categories 700x404\" class=\"wp-image-50376\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Response:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the authorization of request, Magento returns the list of all active categories in the store through API response.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n    \"items\": [\n        {\n            \"id\": 3,\n            \"parent_id\": 2,\n            \"name\": \"Gear\",\n            \"is_active\": true,\n            \"position\": 4,\n            \"level\": 2,\n            \"children\": \"4,5,6\",\n            \"created_at\": \"2020-11-30 12:22:20\",\n            \"updated_at\": \"2020-11-30 12:22:20\",\n            \"path\": \"1\/2\/3\",\n            \"available_sort_by\": [],\n            \"include_in_menu\": true,\n            \"custom_attributes\": [\n                {\n                    \"attribute_code\": \"display_mode\",\n                    \"value\": \"PAGE\"\n                },\n                {\n                    \"attribute_code\": \"is_anchor\",\n                    \"value\": \"0\"\n                },\n                {\n                    \"attribute_code\": \"path\",\n                    \"value\": \"1\/2\/3\"\n                },\n                {\n                    \"attribute_code\": \"children_count\",\n                    \"value\": \"3\"\n                },\n                {\n                    \"attribute_code\": \"url_key\",\n                    \"value\": \"gear\"\n                },\n                {\n                    \"attribute_code\": \"url_path\",\n                    \"value\": \"gear\"\n                }\n            ]\n        },\n    ],\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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 \u2013 get all categories to do that. I hope you will find this guide useful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In case you still have any doubts or queries regarding Magento 2, feel free to comment. I would be happy to help you.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not forget to share this Magento 2 API guide with your developer friends via social media.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading!  <\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-cms-page-content\/\">Magento 2 API \u2013 Get CMS Page Content<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-all-products\/\">Magento 2 API \u2013 Get All Products<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello, Magento peeps! In my last post on&nbsp;Magento 2 API, I provided complete solution to get Magento 2 CMS content through APIs. In case you&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2550","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2550"}],"version-history":[{"count":6,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2550\/revisions"}],"predecessor-version":[{"id":12883,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2550\/revisions\/12883"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}