Retrieve ALL children of specific category via API?
Unsolved
Technical Support
-
Is there a way to retrieve the full list of subcategories for a specific category via the v3 read API?
I see there is a "children" object when fetching a category, but it only includes the first 10 children.
There seem to be some pagination options:
"subCategoriesLeft": 1107, "hasMoreSubCategories": true, "nextSubCategoryStart": 10,
But no way of passing these parameters in the API call.
-
This is one of the socket.io methods that is not available in the v3 read API yet. If you want to load all the subcategories you can do it with a socket.io emit. See below function
async function getSubCategories(cid) { // store current loaded children let subCats = ajaxify.data.children.slice(); let newCats = []; // start from the nextSubCategory index let start = ajaxify.data.nextSubCategoryStart; do { // load the next page newCats = await socket.emit('categories.loadMoreSubCategories', { cid: cid, start: start, }); // move start to next page start += ajaxify.data.subCategoriesPerPage; // add the newly loaded children to our sub categories subCats = subCats.concat(newCats); // we are done if no new categories were loaded } while (!newCats.length); return subCats; }
You can call this function on a category page and it would return all the subcategories of that category.
Copyright © 2024 NodeBB | Contributors