I would like to create a Category List Extension for the Magento Rest Api.
There is a thread posted at stackoverflow:
Create new magento Rest api to get category list in magento
But it shows only a small incomplete piece of code which is not working. It seems that the developer just copied a short snippet from the following extension by Marko Andreini:
https://github.com/marcoandreini/magento-extendedrestapi
But I can't get it to work with Magento 1.9.
I alway get an 403 -access denied when calling /magento/api/rest/categories
I would be very pleased if someone has an idea what's the problem and how to fix it.
this is working for me:
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$result = array();
if (count($_categories) > 0) {
$i = 0;
foreach ($_categories as $_category) {
$katId = $_category->getId();
$result[$i]['katId'] = $katId;
$result[$i]['url'] = $_helper->getCategoryUrl($_category);
$result[$i]['katName'] = $_category->getName();
$result[$i]['katSubs'] = null;
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
$j = 0;
if (count($_subcategories) > 0) {
foreach ($_subcategories as $_subcategory) {
$subKatId = $_subcategory->getId();
$subKatName = $_subcategory->getName();
if ($subKatId && $subKatName && $subKatName != "") {
$result[$i]['katSubs'][$j]['parentKatId'] = $katId;
$result[$i]['katSubs'][$j]['subKatId'] = $subKatId;
$result[$i]['katSubs'][$j]['url'] = $_helper->getCategoryUrl($_subcategory);
$result[$i]['katSubs'][$j]['subKatName'] = $subKatName;
$j++;
}
}
}
$i++;
}
}