# Getting the target user for notification webhook events

**URL:** https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052
**Category:** Development
**Tags:** rest-api
**Created:** [September 19, 2019, 9:45pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052 "2019-09-19T21:45:57Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![phallguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/phallguy/32/150760_2.png) [@phallguy](https://meta.discourse.org/u/phallguy)
#### Post date: [September 19, 2019, 9:45pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/1 "2019-09-19T21:45:58Z")

</div>

I see that webhooks now support notifications which is fantastic. Something we really need. However the payload is missing one critical piece of information - the user the notification is for. In this example payload we can see the author of the post that triggered the notification, but not the user that should receive the notification.

```plaintext
{
  "notification": {
    "id": 119,
    "notification_type": 9,
    "read": false,
    "created_at": "2019-09-18T13:42:21.248Z",
    "post_number": 1,
    "topic_id": 75,
    "fancy_title": "Phallguy should get a notice about this",
    "slug": "phallguy-should-get-a-notice-about-this",
    "data": {
      "topic_title": "Phallguy should get a notice about this",
      "original_post_id": 111,
      "original_post_type": 1,
      "original_username": "Paul_Alexander",
      "revision_number": null,
      "display_username": "Paul_Alexander"
    }
  }
}

```

I’ve looked to see if there’s an API to get the target user from notification id but haven’t found anything documented. Is there a way we can get the target username/id in the notification payload?

For context, we are trying to consolidate notifications from multiple systems into a single experience for our users.

---

<div class="post-metadata">

### Author: ![phallguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/phallguy/32/150760_2.png) [@phallguy](https://meta.discourse.org/u/phallguy)
#### Post date: [September 20, 2019, 5:34pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/2 "2019-09-20T17:34:49Z")

</div>

@Falco or @blake do you have any thoughts on how I can figure out which user a notification is for when received through the new notification webhook?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [September 20, 2019, 5:49pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/3 "2019-09-20T17:49:20Z")

</div>

Just looked at this briefly to see if there was a quick answer, and you are right, it does not look like we have a `get` api endpoint for fetching an individual notification by id, but that wouldn’t be very efficient to call every time anyways.

Most likely this will require a code change to the notification serializer to include the `user_id`/`username` inside of the notification payload, so that a separate api request wouldn’t be necessary.

---

<div class="post-metadata">

### Author: ![phallguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/phallguy/32/150760_2.png) [@phallguy](https://meta.discourse.org/u/phallguy)
#### Post date: [September 20, 2019, 5:57pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/4 "2019-09-20T17:57:22Z")

</div>

We’re using the hosted service at the moment otherwise I’d build my own plugin. Would you folks consider adding the user id/username to then notification payload in the webhook?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [September 20, 2019, 6:25pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/5 "2019-09-20T18:25:10Z")

</div>

Did you check the headers?

---

<div class="post-metadata">

### Author: ![phallguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/phallguy/32/150760_2.png) [@phallguy](https://meta.discourse.org/u/phallguy)
#### Post date: [September 20, 2019, 6:27pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/6 "2019-09-20T18:27:16Z")

</div>

I did - hoping to find some extra meta data in there but didn’t find anything user specific.

```plaintext
Request URL: https://XXX
Request method: POST
Accept: */*
Connection: close
Content-Length: 420
Content-Type: application/json
Host: XXX
User-Agent: Discourse/2.4.0.beta4
X-Discourse-Instance: https://XXX
X-Discourse-Event-Id: 11
X-Discourse-Event-Type: notification
X-Discourse-Event: notification_created
X-Discourse-Event-Signature: sha256=XXX

```

---

<div class="post-metadata">

### Author: ![phallguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/phallguy/32/150760_2.png) [@phallguy](https://meta.discourse.org/u/phallguy)
#### Post date: [September 24, 2019, 10:37pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/7 "2019-09-24T22:37:14Z")

</div>

Checking in to see if you folks have any thoughts/updates. The notification webhook without a target user isn’t really of much use.

---

<div class="post-metadata">

### Author: ![phallguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/phallguy/32/150760_2.png) [@phallguy](https://meta.discourse.org/u/phallguy)
#### Post date: [October 10, 2019, 5:28pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/8 "2019-10-10T17:28:25Z")

</div>

Hey guys have you had a chance to review the issue? Is there any hope that we can get the target user id in the notification event?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [October 15, 2019, 9:59pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/9 "2019-10-15T21:59:31Z")

</div>

I’ve created a pr that will add the `user_id` to the notification webhook json payload:

[https://github.com/discourse/discourse/pull/8195](https://github.com/discourse/discourse/pull/8195)

---

<div class="post-metadata">

### Author: ![albert.casademont](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert.casademont/32/186868_2.png) [@albert.casademont](https://meta.discourse.org/u/albert.casademont)
#### Post date: [July 13, 2020, 3:11pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/10 "2020-07-13T15:11:08Z")

</div>

Hi @blake, would it be possible to also add the user external\_id? We work with Discourse’s SSO and we don’t really have the discourse user ids in our system.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [July 13, 2020, 6:16pm UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/11 "2020-07-13T18:16:53Z")

</div>

Hi Albert!

I think that is a good idea to have and I’ve created commit that will add the external\_id of the user if sso is enabled.

[https://github.com/discourse/discourse/commit/a900c99993aa029230b57d9fd0d96365e1579a21](https://github.com/discourse/discourse/commit/a900c99993aa029230b57d9fd0d96365e1579a21)

Hopefully that helps! It will be added to your site next time it is deployed, which should be sometime this week.

---

<div class="post-metadata">

### Author: ![albert.casademont](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert.casademont/32/186868_2.png) [@albert.casademont](https://meta.discourse.org/u/albert.casademont)
#### Post date: [July 14, 2020, 8:13am UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/12 "2020-07-14T08:13:29Z")

</div>

Wow, that was fast! Thanks a lot, much appreciated :smiley: Do you know what’s the aprox ETA for those changes to make it to the hosted Discourse servers?

---

<div class="post-metadata">

### Author: ![albert.casademont](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/albert.casademont/32/186868_2.png) [@albert.casademont](https://meta.discourse.org/u/albert.casademont)
#### Post date: [July 14, 2020, 8:49am UTC](https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052/13 "2020-07-14T08:49:59Z")

</div>

Oh nevermind, didn’t read the last sentence :sweat_smile:. Thanks again!!
