Get all categories via API including subcategories

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.

「いいね!」 3

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.

「いいね!」 5

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.

「いいね!」 1

I see that subs have parent_category_id from sites.json. I wonder why then categories.json is only root level.

「いいね!」 2

Note, you can now get all categories and sub-categories from categories.json with
/categories.json?include_subcategories=true

「いいね!」 1