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.
site.json scheint der Weg zu sein, um eine Liste aller Kategorien zu erhalten. Wird dies irgendwo auf docs.discourse.org erwähnt? Ich habe die Dokumentation durchsucht, um eine Möglichkeit zu finden, die Namen der Unterkategorien zu erhalten, konnte sie aber nicht finden. Oder gibt es einen besseren Weg?
Eine API-Anfrage an site.json ist der richtige Weg, um eine Liste von Kategorien zu erhalten, die Unterkategorien einschließt. Wenn Sie zudem möchten, dass private Kategorien in der Antwort auf die Anfrage an site.json enthalten sind, müssen Sie eine authentifizierte API-Anfrage stellen.
Ich sehe in der Dokumentation keinen Hinweis auf site.json. Da categories.json keine Unterkategorien zurückgibt, ist die Beschreibung der categories-Route in der Dokumentation nicht korrekt; sie besagt, dass die Route alle Kategorien zurückgibt. Ich werde das beheben.