The issue of API requests not updating the User#last_seen_at date has been discussed. Initially, jandres reported the issue after updating from 2.2.0.beta3 to 2.3.0.beta1. However, david clarified that the expected behavior is for API requests not to update the last_seen time, as it was a bug that previously caused this to happen erroneously.
david suggested a workaround by making a request with the “X-Requested-With” header containing “XMLHttpRequest” and “DISCOURSE_VISIBLE” as “true”, but noted that this is not a supported way to use the API.
jandres and eviltrout questioned the logic behind not considering API requests as visits, with eviltrout proposing the idea of accepting a HTTP header or parameter to treat the user as a regular user.
david agreed with this idea and later implemented a solution, allowing API requests to update the last_seen time when the DISCOURSE_VISIBLE="true" header is set. This change is documented in a GitHub commit.
Last version is ignoring request coming from API to update user visits stats in forum.
Other stats like ‘number of likes’ or ‘pageviews’ are right, but it seems that something has happened with user visit stats.
Before, when i pulled for latest topics or post in topics, it updated the User#last_seen_at dates, but now there are now 9 days ago, I don’t have any new visit from my users, when normally i have hundreds.
When i visit the user active list page in ‘/admin/users/list/active’, i see the ‘seen’ column fixed to date when i did the update.
I updated from 2.2.0.beta3 to last current version 2.3.0.beta1 and i didn’t have any issue while updating.
No, there isn’t one. If you have control over the API server you could try and “trick” discourse into updating last seen for the request. From the code I quoted above you can see how it works.
So you could make a request with “X-Requested-With" header containing “XMLHttpRequest” (to trick the xhr? bit), and “DISCOURSE_VISIBLE” as “true”.
Note that this wouldn’t be a “supported” way to use the API, but I don’t foresee any problems.
The API is typically used for things where users are not present - for example the official Discourse mobile app uses the API to check for new topics in the background.
I would expect a user viewing something via API to be the same as if they hit that API via their browser.
I feel like that is an exception to the principle of least surprise.
I understand why that decision was made, but perhaps we could accept a HTTP header or parameter that indicates if we want to treat the user as a regular user?