# Microsoft Teams and Watcher

**URL:** <https://discuss.elastic.co/t/microsoft-teams-and-watcher/141016>\
**Category:** Elasticsearch\
**Created:** [July 22, 2018, 2:00am UTC](https://discuss.elastic.co/t/microsoft-teams-and-watcher/141016 "2018-07-22T02:00:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ron\_3](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Ron\_3](https://discuss.elastic.co/u/Ron_3)\
**Post date:** [July 22, 2018, 2:00am UTC](https://discuss.elastic.co/t/microsoft-teams-and-watcher/141016/1 "2018-07-22T02:00:45Z")

</div>

We're trying to alert to MS teams via a Watcher Webhook, we've played with this a few ways without any luck.

Based on our research you really just need 3 values to post to teams.

**In Headers**

- "Content-Type": "application/json"

**In the body**

- "summary" : "Alert",
- "text" : "bad stuff happened "

The issue is, putting the values in they body. Most everything we've found says that the "Body" field is a string and you can't use json it . When we try some mash of {{#toJson}}ctx.payload.however\_you\_named\_it{{/toJson}} it fails hard when we try to put summary and text in the payload.

Our example action (of maybe how it should work):

```
"actions": {
    "MS_Teams": {
        "webhook": {
            "method": "POST",
            "host": "outlook.office.com",
            "port": 443,
            "path": "/LONG_KEY_GOES HERE",
            "headers": {
                "Content-Type": "application/json"
            },
            "body": {
                "summary": "Alert",
                "text": "stuff that happened"

            }
        }
    }
}

```

}

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 23, 2018, 7:00am UTC](https://discuss.elastic.co/t/microsoft-teams-and-watcher/141016/2 "2018-07-23T07:00:18Z")

</div>

hey,

so indeed your solution to go with `#toJson` is the correct one, as the `body` field from the webhook only supports a string.

The correct way would be to use a `transform` in your action to properly create the payload via a painless script then just have `{{#toJson}}ctx.payload{{/toJson}}` in your `body` field.

your transform would be something like

```auto
"transform" : {
  "script" : "result = [:], result.summary = ctx.payload... ; result.text = 'My text' ; return result"
}

```

hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 20, 2018, 7:00am UTC](https://discuss.elastic.co/t/microsoft-teams-and-watcher/141016/3 "2018-08-20T07:00:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
