How to get all latest/top messages in non-private categories?

Here’s my situation: I am using Discourse via SSO. A member of my main site may have never visited the forums (yet), but I want to show them the latest/hot topics, to entice them to click and see what they’re missing.

However, until they enter the forums for the first time, they don’t have a Discourse profile. (It’s created on initial sign-in, as SSO is designed to work.)

This leads to a problem: if I ask Discourse for the latest activity, I either have to specify a valid user (which doesn’t exist in this case), or I get back a list that includes topics that can be in private categories (protected by group).

Currently I deal with this by having a hardcoded list of which categories should be excluded, and I walk through the list and exclude any topics that live in those categories. But it’s not ideal. And the pinned topics (“Welcome to the new forums” and such) always end up at the top of the list… which I guess I can filter those out as well… but it all feels very hacky. :slight_smile:

Any suggestions for a more elegant way to accomplish what I’m trying to do in a more elegant manner?

You could fall back to the feeds (latest.rss/top.rss)?

1 Like

That’s a clever idea, but I don’t think it’ll work for me since my forum is completely private. So if I try to fetch the RSS feed without having a valid Discourse session , it redirects to a login page.

Then create a dummy user with the minimum level of access and use their views as a fallback?


Create a new user without any special group membership and do API requests for latest using this unprivileged user.

1 Like

Hmm, that’s not bad. It’s still a bit hacky, but I think it’s slightly less hacky than what I’m doing now. Keeping a “phantom basic user” around means, at least, I don’t have to manually maintain a list of Discourse category IDs in my main site’s code.