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.

2 Likes

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: wp-discourse/plugin-utilities.php at master · discourse/wp-discourse · GitHub.

3 Likes

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 Like

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

1 Like