Can anyone help me display categories and their subcategories using the REST API?
I have tried this url:
http://localhost/magento/api/rest/products/:productId/categories
But it displays category ID instead of what I'd need, i.e. something like this:
http://localhost/magento/api/rest/categories
Thanks in advance.
2 Answers
Answers 1
/api/rest/products/:productId/categories
This should retrieve a list of categories assigned to a specific product. Unfortunately, this won't lead you to the elegant solution you deserve.
If you want a list of categories you may have to use the soap api to retrieve the categories using the catalog_categories.tree method. I realize "use some other api" is the worst kind of answer but, it is what magneto currently offers.
The alternative is to extend the stock api with your own restful patchwork, but, life is short.
If you really want to do something like that then, this other Stack Overflow question will help get you started: Create new magento Rest api to get category list in magento
Answers 2
There is indeed still nothing to be found either in Magento 1.x API guide either in the code.
You can clearly see in the folder structure of the Mage_Catalog
module that the model representing categories are still only sub models of the product, so it's main goal is still "only" to be able to know in which categories a specific product is linked to.
And the code of this category model being of class Mage_Catalog_Model_Api2_Product_Category_Rest
doesn't look like anything as changed from the previous answer, sadly (around line 61 in the latest version 1.9.2.4) :
protected function _retrieveCollection() { $return = array(); foreach ($this->_getCategoryIds() as $categoryId) { $return[] = array('category_id' => $categoryId); } return $return; }
And I am unsure if Magento is still going to put any effort in REST API on the version 1.x of the framework.
Although there seems to be hope in Magento 2.x API list listing those available methods :
DELETE /V1/categories/:categoryId
GET /V1/categories/:categoryId
POST /V1/categories
GET /V1/categories
PUT /V1/categories/:id
PUT /V1/categories/:categoryId/move
Also the code offers possibilities to get the categories tree.
See here and there.
So it is definitely something possible under Magento 2.x
0 comments:
Post a Comment