# User post\_count is zero in webhook for a user that has posts

**URL:** https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574
**Category:** Development
**Tags:** webhooks
**Created:** [June 7, 2023, 7:28pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574 "2023-06-07T19:28:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dpb](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dpb](https://meta.discourse.org/u/dpb)
#### Post date: [June 7, 2023, 7:28pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/1 "2023-06-07T19:28:02Z")

</div>

We have a webhook on the event “user\_logged\_in”. The Payload contains the property `post_count` for the user that just logged in. Although the user did write 2 posts, the payload reads `post_count: 0`. This looks like a bug to me.

The receiver of the webhook needs this user stat to decide how to proceed.

The only similar topic I found is this one, might be related but does not talk about the same API: [Category post\_count not incrementing](https://meta.discourse.org/t/category-post-count-not-incrementing/230788)

---

<div class="post-metadata">

### Author: ![dpb](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dpb](https://meta.discourse.org/u/dpb)
#### Post date: [June 7, 2023, 7:39pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/2 "2023-06-07T19:39:06Z")

</div>

I have to correct myself: The `post_count` is not _always_ zero. When checking with my own user, the `post_count` was plausible (though I don’t know whether it is accurate or not).

But there is a user on our site, let’s call it user #1234, for which the following holds:

- `SELECT * FROM posts WHERE user_id=1234` returns two entries in the table. These are the posts that are also listed in the user’s profile activity page
- The webhook payload, when this user logs in or out, contains `"post_count": 0`.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [June 8, 2023, 11:47am UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/3 "2023-06-08T11:47:14Z")

</div>

Hi @dpb,

I tested, and the post count isn’t updated in real-time.

~~My guess is that there’s a Sidekiq job that takes care of that periodically, but I don’t know which one.~~  
It doesn’t seem there’s a specific related Sidekiq job 🤔  
But I read that this stat is updated at least once a day.

A GET request to [https://your-discourse.org/u/username.json](https://your-discourse.org/u/username.json) will return the right number, though.

If you want a reliable number, make such a request after receiving the webhook payload.

---

<div class="post-metadata">

### Author: ![dpb](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dpb](https://meta.discourse.org/u/dpb)
#### Post date: [June 8, 2023, 4:29pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/4 "2023-06-08T16:29:57Z")

</div>

Thanks @Canapin for suggesting the GET request to the API.

> [@Canapin](#):
>
> But I read that this stat is updated at least once a day.

Well, in our case, the posts have been there for well over a month by now.

Maybe the component that updates this number stopped working at some arbitrary time during one of the updates?

---

<div class="post-metadata">

### Author: ![dpb](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dpb](https://meta.discourse.org/u/dpb)
#### Post date: [June 8, 2023, 4:36pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/5 "2023-06-08T16:36:27Z")

</div>

> [@Canapin](#):
>
> A GET request to [https://your-discourse.org/u/username.json](https://your-discourse.org/u/username.json) will return the right number, though.

Tested it, does not work either. Contains the same information: `post_count: 0`

---

<div class="post-metadata">

### Author: ![dpb](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@dpb](https://meta.discourse.org/u/dpb)
#### Post date: [June 8, 2023, 4:46pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/6 "2023-06-08T16:46:10Z")

</div>

Maybe there is a confusion with “topics” and “posts”. I expected that creating a new topic is just a special type of post. The database structure supports that.  
But when checking the user profile statistics, they say something along the lines “2 topics created, 0 posts created”.  
So maybe the “post\_count” that I get is rather the _number of replies to topics_ than the number of all posts?  
On the other hand, there is a date “last\_posted\_at” which contains the date when the last topic was created. So at least, there is some inconsistency in naming here. I would expect the number “post\_count” to include first posts in new topics, as well.

Anyway, whether this is intended behavior or not, I do not find a `topic_count` or alike in the user json. How do I find out the total number of posts, including new topics?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2023, 5:21pm UTC](https://meta.discourse.org/t/user-post-count-is-zero-in-webhook-for-a-user-that-has-posts/267574/7 "2023-06-08T17:21:02Z")

</div>

> [@dpb](#):
>
> Anyway, whether this is intended behavior or not, I do not find a `topic_count` or alike in the user json. How do I find out the total number of posts, including new topics?

My json knowledge is a little fledgling but I can see the `topic_count` in [https://meta.discourse.org/u/dpb/summary.json](https://meta.discourse.org/u/dpb/summary.json)

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/6/9/16906a8c9a28c92fd8c6b295e2f55e4c6c79492f.png)
