What's a Post? (Discourse API question)

I’m trying to accurately gauge and report activity from a forum that I am running using Discourse. I think I fundamentally don’t understand what a Post is.

On the API, there’s Topics and Posts. For example, if I want to get Posts, I can use filter=5

/user_actions.json?offset=0&username=USERNAME&filter=5

(Can anyone tell me what is “offset”?)

Here’s the mystery. Posts don’t appear to include Topics. Is this the expected behavior?

What are Posts in the relation to Replies? They do not appear to be a superset.

Are posts in the API the same as we get in the report (Admin → Reports → Posts)?

reports-posts

Any help appreciated.

1 Like

As far as I can tell, the filter=5 for posts on /user_actions.json?offset=0&username=USERNAME&filter=5 does not correspond to the Posts in the report. It looks like the Posts on the report includes both the posts (filter=5) and topics (filter=4).

I’m assuming that posts are supposed to be replies + topics. It would be nice if someone more knowledgeable could confirm this.

If this is the case, I can try to use replies (filter 6) and topics (fliter 4). However, I’m a bit concerned about this as the report in the Discourse manager is giving the correct, expected numbers.

Try and search for an example of using the Discourse API to produce reports.

1 Like

Yes, posts are within a topic. So searching for new posts will not search for new topics.

When you create a Topic you have also created a Post - the first Post is part of the Topic.
However, all subsequent Replies are also considered Posts - you are posting your replies. :slightly_smiling_face:

As for the offset and whether the posts in the API are the same as in Admin → Reports → Posts, I’ll leave that to someone else.

1 Like

Is this any help?

3 Likes

First, thank you for your help.

Using the /user_actions.json?offset=0&username=USERNAME&filter=5, I do not seem to be getting a post counted if it was the first post of a topic.

I may be using the API wrong.

I have a test account with 7 activities.

  • 3 topics, each with a post
  • 4 replies to existing topics.

When I filter for “posts”, I get a count of 4, not the expected 7.

to get the expected post count of 7, I think I need to add “replies” and “topics”.

from what I understand, I think the filter" of 5` should return both the posts that are the first post of a topic as well as the replies, right?

I’d love to get some help trying to understand how to pull the posts count for specific users with the API.

 query = {'username': username, 'filter': '5'};

  var response = await getRequest(
      path: '/user_actions.json',
      queryParameters: query);

That’s correct. All topics have a first post as part of the topic creation. One couldn’t very well create a topic with only a topic header. That first post isn’t counted as a post (reply) in a post query (filter-5).

When you query for posts, that’s a query for new Replies to Existing Topics - excluding the OP. That is the expected behavior - to show only the new posts.
To include Topics (created by that user) as part of the query, then Filter=4 should return the topics that user created (including the OPs as part of the count [3]), and their replies [4]. That would return the 7 you see in the report. 3 Topics created + 4 replies to give a count of 7 (3 OPs + 4 Replies).

Anyone else more knowledgeable please feel free to jump in.

4 Likes

@JimPas , thank you for your help. It is very useful. With this knowledge, I’m moving forward with the application dashboard with more confidence. Have a nice day. Very nice of you to help a stranger like me.

3 Likes

Same here, @JimPas, very helpful and very much appreciated. Thank you.

2 Likes