The /categories.json
API call returns only top-level categories, at least on my server. I can read subcategories using /c/<id>.json
but I don’t know how to discover those IDs.
To get all categories and subcategories from the API, you need to make a request to /site.json
. If you don’t mind looking at PHP/WordPress code, there’s an example API request to get all categories here: https://github.com/discourse/wp-discourse/blob/master/lib/plugin-utilities.php#L104.
Terrific, thank you!
I notice that the category record returned doesn’t have a parent category. If it did, a flattened list from /catgories.json
of all categories would be I think a less-surprising result, as opposed to only the root level.
I see that subs have parent_category_id
from sites.json
. I wonder why then categories.json
is only root level.
Note, you can now get all categories and sub-categories from categories.json
with
/categories.json?include_subcategories=true