In a discussion titled ‘How to get a category name with the ID via API’ under the Dev category, users explore how to retrieve category names and slugs using the Discourse API. anon89120937 seeks a way to get subcategory details (name/slug) from IDs using the PHP Discourse API client. michaeld references an old thread suggesting /site.json as the solution, citing riking. anon89120937 asks if this is implemented in the PHP client; michaeld confirms it isn’t but offers to add it. anon89120937 shares a custom getCategoryById function using /site.json, which riking advises caching for efficiency. Later, anon89120937 updates with a more efficient approach: fetching /site.json once and parsing all categories and subcategories into a structured array, referencing their GitHub implementation. nedbat notes the lack of documentation for site.json and asks if there’s a better method. simon confirms /site.json is the correct approach, especially for subcategories, and clarifies that authenticated requests are needed to include private categories. He also acknowledges the docs are outdated — categories.json doesn’t return all categories as claimed — and commits to fixing the documentation.
I use Discourse API client for PHP (by @michaeld I guess) and I can’t find how to get a category name/slug with only with an ID.
I need it to display (slug and id) of all our categories and their sub-categories.
But when I get the categories list, the only information about sub-categories is their id.