Discourse API: Get Categories Related to Posts

Hello!

I am developing a search autocomplete external to Discourse, to be used in other websites connected to our network, where I will be able to output in the same autcomplete a mix of results from Discourse and from other sources (in particular with shop results).

I am using the Discourse API for Search, and I can get posts, topics, and blurbs without issues. The only information I am missing right now is the category name and possibly “color”, as it is shown in the search popup within Discourse.

Is there some way to get categories connected to the posts through a single API request? Or should I devise some alternate method?

The only way I can use right now is to send two different queries, one for the category list, the other for the actual forum search.

Thanks.

2 Likes

You will need to use a separate api call to get a list of categories, but that is probably something you can cache locally somehow so that you won’t have to query for it along with every search query.

3 Likes

Blake, thanks for your reply. Indeed, this is the route I went - locally cached categories.

For people doing similar stuff to what I am doing: since in my case I needed all the categories and subcategories, I also ended up using the site.json API point instead of categories.json (which seems to return only top level categories).

3 Likes