Who's online "API"?

AI-generated summary

The discussion revolves around accessing the number of users online through an API. mentalstring is looking to fetch this data using an external tool and inquires about a possible API request or route to achieve this. david responds by suggesting two options:

  • Using the /whosonline/get.json endpoint, but notes that this is not a public API and may change.
  • Creating a data explorer query, such as SELECT id AS user_id FROM users WHERE last_seen_at >= NOW() - INTERVAL '5 minutes', and calling it with the Discourse API.

We are looking into monitoring the activity of the forum (number of users online over time) using an external tool like grafana. We already use the whos-online plugin so I was wondering if there’s a way we can fetch the number of online people (as calculated by the plugin) through some API request or route? It’s fine if it returns more than needed as it can be parsed.

Or, is there perhaps a simpler way to do this with the existing core API that I’m not aware of?

You can pull the data from the whos-online plugin at /whosonline/get.json, but note that the URL and the data format shouldn’t really be considered a public API - it could be removed or changed at any time.

Another option is to make a data explorer query and call it with the API. A query like this should do essentially the same thing as the whos-online plugin:

SELECT id AS user_id 
FROM users 
WHERE last_seen_at >= NOW() - INTERVAL '5 minutes'