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"]))