Discrepancy in API data vs WebUI data

I want to get the data of a specific user via API. Basically, I want to know how many replies the user gave since he joined the forum. I used the following code (basically I fetched all the user_actions where the action_type=5 and then printed the number of such records). The final output did not matched with what I see in the webUI. Can anyone explain why this might be happening?

import requests, time

defaultHost = #your_default_host

# Headers for authentication
headers = {
    'Api-Key': #YOUR_API_KEY,
    'Api-Username':#YOUR_API_USERNAME
}


# increment the offset by 30 each time. The loop should break when the number of elements in the response is less than 30
offset = 0
data_dict ={"user_actions":[]}
username = #username_for_which_we_want_to_fetch_the_data

# filter=5 # For the "user_replied_to_a_topic"

while True:
    time.sleep(0.2)
    endpoint = f'https://{defaultHost}/user_actions.json?username={username}&offset={offset}&filter=5'
    # Make the request
    response = requests.get(endpoint, 
                            headers=headers)

    # Check the response
    if response.status_code == 200:
        data = response.json()
        num_elements = len(data["user_actions"])
        data_dict["user_actions"].extend(data["user_actions"])
        offset+=30
        if num_elements<30: 
            break    
    else:
        print(f'Error: {response.status_code}')
        break

print(len(data_dict["user_actions"]))

Just a guess (didn’t have a look at the core files and database). Maybe one value takes the first posts (which are not replies) into account, whereas the other only returns replies.

Also, why don’t you use a data explorer query to return this data? I think it would be way more convenient unless I’m missing something. :thinking:

1 Like

Can you clarify which values are you talking about?

Yes if the API doesn’t give correct output, then the Data Explorer is the ultimate solution. But the bigger question is: Why the API and webUI doesn’t return exactly same data?

yes, I have done it as you may see in the code I posted:

    endpoint = f'https://{defaultHost}/user_actions.json?username={username}&offset={offset}&filter=5'
1 Like
  1. The value returned by Discourse’s interface

  2. The value returned by your script

On which page?