Possible to use system API key to get "hot" and "latest" topics for specific user?

Here’s my use case: I want to show the top 5 latest and hottest topics on my forum home page. I need it to be filtered by what is appropriate for a particular Discourse user - for example, some of my users have access to a private category (which has topics that should bubble up to latest/hottest) and some other users don’t.

Currently when I call the Discourse API to get what I need, I use a system API key. This gives me results that include not only the hidden categories, but also always includes any globally-pinned topics at the top of the list (even though a user may have long unpinned those).

So I think you can see why I need the latest/top for a specific user, not across the entire forum.

And if this functionality is possible by calling with a user API key, then it’s a different problem-- it seems very clumsy to have to create a user API key (programmatically) every time I want to retrieve these results for a user. (And presumably destroy the API key right after, since I don’t need it for anything else.) Is that the only way?

I propose a solution where if you call latest.json or top.json with a system API key, those endpoints could take an optional user ID parameter to limit the results.

If you create an all users api key you can specify the user it runs as. It then impersonates that user.


Hi @sam oh, fantastic! What’s the endpoint, then? I do have an all-users system API key.

The normal endpoint, that gives me all latest, unfiltered:


User-specific endpoints that I’ve tried, that don’t work (where username is the name of a user in my forums):

/latest/4.json (using user ID instead of username)

I can’t seem to find it :-\


You should specify the username in Api-Username like the example in the above doc.


Ahaaaaa thanks. I see now.