Is there is any open API for getting similar topic in discourse?

I need a api that give me similar topics.
My requirement - If i have a topic title then i will get the similar topics.

You will see that if you request the JSON for a topic, it has a section called suggested_topics.


From title to topic ID can be done using search:



I think you should use: so that related articles are related to each other. From title to topic ID can be done using search:

Its working on meta.discourse but not on my forum. Our forum is
If i will then no result was there

That seems like a private community so unauthenticated requests will not return any data. It works on Meta using because the content is publicly viewable.

See Discourse API Documentation and Using the Discourse API Ruby Gem for more info on authenticating your requests with an api_key and api_username.

1 Like

That specific topic only has one post so there is no post 2.
It needs to be

You can always use t/<topic_id>/1.json

And indeed, you need to use an API key since you have a closed community.


Would this also work somehow for arbitrary text passed-in from some external source? In other words can I use the existing similarity match function to return a list of potential existing topics based on text provided to the API, rather than based on an actual, existing topic that has to be specified?

Sorry if this is a dumb question. I’m not a developer, but looking to gather some info prior to talking to one for a feature request I’m considering. The idea is to connect e.g. Intercom (although in this case an open source alternative) with a Discourse forum so that when someone types a question into the chat box, it can look up potential Discourse topic matches and provide them as possible places to find their answers or direct their questions. Similar to how Intercom can already access a knowledgebase to provide potential answers.

Well anything in Discourse can be automated because Discourse is a JavaScript app, not a traditional “web pagee”. In this case, you’d replicate the user interface actions you take from the advanced search page, like so:

1 Like

Yeah, I thought that might be the case. So essentially the Similar Topic functionality in the composer preview is just like normal Search, but passing the contents of the user’s topic as search criteria?

In my use case I’d pass the user’s message contents to the normal Search function, and return X number of hits as possible relevant topics? (the terminology I’m using may not be quite right here, I just need to know if the basic idea is correct :grinning_face_with_smiling_eyes:)

1 Like

Use the web inspector as detailed in that topic to watch what happens as you write in the composer and trigger the suggested similar topics dialog.

I believe that it is materially different from “normal” site search, as it marks the search as “give me anything that matches any of these, and use frequency / multiple matches etc to order the results”.


Thanks! I did a little testing before your reply and did notice that search and similar topic results differed a bit, so that’s interesting. This here should be enough info to see if I can make the case for Discourse to the group I am in discussion with though.