Mismatch Between API and WebUI Data for User Activity

I came across this post visit.meta.discourse.org/t/discrepancy-in-api-data-vs-webui-data/347920 and noticed a similar issue in my own project when fetching user activity data through the API.

I’m trying to calculate the total number of replies a specific user has made on the forum. I’m using the /user_actions.json endpoint with filter=5 (replies), and while the API request executes successfully, the count I get is always lower than what’s displayed in the WebUI for the same user.

Here’s an example of my code:

import requests

host = "example.discourse.org"
headers = {
    'Api-Key': "YOUR_API_KEY",
    'Api-Username': "YOUR_API_USERNAME"
}

username = "target_user"
offset = 0
total_replies = 0

while True:
    endpoint = f'https://{host}/user_actions.json?username={username}&offset={offset}&filter=5'
    response = requests.get(endpoint, headers=headers)
    
    if response.status_code == 200:
        data = response.json()
        total_replies += len(data["user_actions"])
        if len(data["user_actions"]) < 30:
            break
        offset += 30
    else:
        print(f"Error: {response.status_code}")
        break

print(f"Total Replies: {total_replies}")

Despite fetching all available pages of user actions, the API consistently reports fewer replies than what is shown in the WebUI. I’ve double-checked the filter and ensured no requests were skipped, yet the discrepancy persists.

Could this be due to API limitations, discrepancies in how replies are counted in WebUI vs API, or possibly an issue with archived or hidden data not being returned via the API? Has anyone faced a similar issue and found a reliable way to reconcile API and WebUI data? Any insights would be greatly appreciated!

1 Like