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

**URL:** https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352
**Category:** Development
**Created:** [26 april 2020 om 13:44 UTC](https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352 "2020-04-26T13:44:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [26 april 2020 om 13:44 UTC](https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352/1 "2020-04-26T13:44:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [27 april 2020 om 01:49 UTC](https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352/2 "2020-04-27T01:49:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [27 april 2020 om 06:55 UTC](https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352/3 "2020-04-27T06:55:43Z")

</div>

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

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/e/9e9fb6de1a6540d4d130e716e161cff3ec15304d.png)

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

`/latest.json`

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

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

I can’t seem to find it :-\

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [27 april 2020 om 07:03 UTC](https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352/4 "2020-04-27T07:03:31Z")

</div>

> **[Discourse API Docs](https://docs.discourse.org/#authentication)**

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

---

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [27 april 2020 om 07:06 UTC](https://meta.discourse.org/t/possible-to-use-system-api-key-to-get-hot-and-latest-topics-for-specific-user/149352/5 "2020-04-27T07:06:43Z")

</div>

Ahaaaaa thanks. I see now.
