While creating a mobile application we need to get the data of the list page through the Magento 2 category page rest API.
In this sequence, I am telling you the steps here, using which you can get the information of the category page through Magento 2 API.
If you are searching Magento 2 REST API to get all categories where the is_active attribute is true in that case also you can use the below api.
You can also get the data of the enabled category of any store through the default REST API of Magento 2 given below
This Magento API behaves in such a way that you can get only the data of the active category, then you can use this API.
If a category is disabled, its attribute will not be active
Category Collection REST API Magento 2
This Magento 2 REST api of the category page lets you get category collection through store view code.
Through this, you can get the collection of entire store category collection details.
Endpoint:
https://www.wishusucess.com/rest/default/V1/categories
Method: GET
Header
- Content-type: application/json
- Authorization: Bearer Admin Token
Authorization: Not required
Response:
{ "id": 2, "parent_id": 1, "name": "Default Category", "is_active": true, "position": 1, "level": 1, "product_count": 1181, "children_data": [ { "id": 38, "parent_id": 2, "name": "What's New", "is_active": true, "position": 1, "level": 2, "product_count": 0, "children_data": [] }, { "id": 29, "parent_id": 2, "name": "Promotions", "is_active": false, "position": 6, "level": 2, "product_count": 0, "children_data": [ { "id": 30, "parent_id": 29, "name": "Women Sale", "is_active": true, "position": 1, "level": 3, "product_count": 224, "children_data": [] }, { "id": 31, "parent_id": 29, "name": "Men Sale", "is_active": true, "position": 2, "level": 3, "product_count": 39, "children_data": [] }, { "id": 32, "parent_id": 29, "name": "Pants", "is_active": true, "position": 3, "level": 3, "product_count": 247, "children_data": [] }, { "id": 33, "parent_id": 29, "name": "Tees", "is_active": true, "position": 4, "level": 3, "product_count": 192, "children_data": [] } ] }, { "id": 37, "parent_id": 2, "name": "Sale", "is_active": true, "position": 6, "level": 2, "product_count": 0, "children_data": [] } ] }
Read more: Get Product Image URL Via Magento 2 REST API
Get All Category Page Data Via API in Magento 2
There is not much difference between the first and this API, but through this API you can get the complete category data of any Magento 2 website.
Using this REST API of Magento, you can easily get any categories and their subcategories across the store
Endpoint:
https://www.wishusucess.com/index.php/rest/V1/categories/
Method: GET
Header
- Content-type: application/json
- Authorization: Bearer Admin Token
Authorization: Not required
Response:
{ "id": 2, "parent_id": 1, "name": "Default Category", "is_active": true, "position": 1, "level": 1, "product_count": 1181, "children_data": [ { "id": 38, "parent_id": 2, "name": "What's New", "is_active": true, "position": 1, "level": 2, "product_count": 0, "children_data": [] }, { "id": 29, "parent_id": 2, "name": "Promotions", "is_active": false, "position": 6, "level": 2, "product_count": 0, "children_data": [ { "id": 30, "parent_id": 29, "name": "Women Sale", "is_active": true, "position": 1, "level": 3, "product_count": 224, "children_data": [] }, { "id": 31, "parent_id": 29, "name": "Men Sale", "is_active": true, "position": 2, "level": 3, "product_count": 39, "children_data": [] }, { "id": 32, "parent_id": 29, "name": "Pants", "is_active": true, "position": 3, "level": 3, "product_count": 247, "children_data": [] }, { "id": 33, "parent_id": 29, "name": "Tees", "is_active": true, "position": 4, "level": 3, "product_count": 192, "children_data": [] } ] }, { "id": 37, "parent_id": 2, "name": "Sale", "is_active": true, "position": 6, "level": 2, "product_count": 0, "children_data": [] } ] }
REST API for All Category Details With Image File
In this API, you can also get the image URL of each category simultaneously.
Rest of the details will remain the same as before API.
Magento 2 API, with the help of which all the category data of any store along with the image of each category is also available
Endpoint:
https://wishusucess.com/index.php/rest/V1/categories/list?searchCriteria[filterGroups][0][filters][0][field]=parent_id&searchCriteria[filterGroups][0][filters][0][value]=2
Method: GET
Header
- Content-type: application/json
- Authorization: Bearer Admin Token
Authorization: Not required
Response
{ "items": [ { "id": 3, "parent_id": 2, "name": "Gear", "is_active": true, "position": 4, "level": 2, "children": "4,5,6", "created_at": "2022-01-20 14:12:16", "updated_at": "2022-01-20 14:12:17", "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" } ] }, { "id": 37, "parent_id": 2, "name": "Sale", "is_active": true, "position": 6, "level": 2, "children": "", "created_at": "2022-01-20 14:15:55", "updated_at": "2022-01-20 14:15:55", "path": "1/2/37", "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/37" }, { "attribute_code": "children_count", "value": "0" }, { "attribute_code": "url_key", "value": "sale" }, { "attribute_code": "url_path", "value": "sale" } ] }, { "id": 38, "parent_id": 2, "name": "What's New", "is_active": true, "position": 1, "level": 2, "children": "", "created_at": "2022-01-20 14:15:55", "updated_at": "2022-01-20 14:15:55", "path": "1/2/38", "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/38" }, { "attribute_code": "children_count", "value": "0" }, { "attribute_code": "url_key", "value": "what-is-new" }, { "attribute_code": "url_path", "value": "what-is-new" } ] } ], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "parent_id", "value": "2", "condition_type": "eq" } ] } ] }, "total_count": 3 }
Similar Posts:
How to Get New Arrival Product REST API in Magento 2
Create Account REST API : How to Create an Account of Customer, Admin
Suggested Post:
BMLT Course in Hindi: Scope and Future Career in BMLT, Eligibility