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

סיכום מבוסס בינה מלאכותית

In a discussion titled “How to get all latest/top messages in non-private categories?” within the Dev category, pnoeric describes a challenge: they want to display the latest or top forum topics to users of their main site who haven’t yet visited the Discourse forum (and thus lack a Discourse profile). Since their forum is private, API requests without a valid session return login redirects or include private-category topics. Their current workaround—hardcoding excluded categories and filtering pinned topics—feels hacky. Stephen suggests using RSS feeds (latest.rss/top.rss), but pnoeric notes these also require authentication. Stephen and Falco then propose creating a dummy or unprivileged user to make API requests on behalf of anonymous visitors. pnoeric agrees this is a slightly cleaner solution than maintaining hardcoded category exclusions, as it avoids syncing category IDs between systems—though still somewhat hacky, it’s an improvement.

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)?

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.

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.