User kittenwater sought assistance in reverse-engineering the Discourse API to mark posts as read via the /topics/timings endpoint. Their initial attempts using a nested JSON timings object returned a 200 status code but failed to update the read history. Canapin suggested altering the payload format, which kittenwater tested without success. Eventually, Canapin provided a working code snippet that successfully updated the individual post read counts and the user’s activity log.
However, kittenwater noted that while post counts updated, the “topics read” metric did not. Canapin hypothesized that this discrepancy was due to a delayed background job (Sidekiq) updating statistics for performance reasons. Moin added that these stats typically update hourly or daily depending on the view. Since kittenwater was a regular user on a production site without access to the admin scheduler, they could not manually trigger the job. Canapin recommended setting up a local or VPS instance to better reverse-engineer the API, as normal users lack the necessary permissions to force these updates immediately.
def load_topics(session, page):
print(f"[Topics] Loading page {page}")
r = session.get(f"https://{hostUrl}/latest.json?page={page}")
if r.status_code != 200:
return []
return [{"id": t["id"], "posts_count": t["posts_count"]} for t in r.json()["topic_list"]["topics"]]
timings = {
str(i): 60000
for i in range(1, post_count + 1)
}
payload = {
"topic_id": topic_id,
"topic_time": post_count * 60000,
"timings": timings
}
# Use json=payload to send as application/json
r = session.post(url, json=payload, headers = {
"X-CSRF-Token": csrf,
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/json"
}
)
I can say with 100% certainty that this statement is true!
The posts read has updated several times but the topics read hasn’t. Are they on different intervals? It’s been ~20 hours since and the posts read count keeps increasing but the topics read doesn’t.
I just want to try to reverse engineer the endpoints! It’s cool.
I think I should wait a bit before coming back and seeing if the values have changed
The site I’m using has that disabled and will always return “A list of community members showing their activity will be shown here. For now the list is empty because your community is still brand new!”
In his case you can’t. Being a regular user isn’t ideal to reverse-engineer the API.
If you can, try a local dev install or a production install on a cheap VPS (a 3-4$ server is alright), since Discourse doesn’t require a hostname or SMTP anymore.