# Use JSON in Watcher webhook body

**URL:** <https://discuss.elastic.co/t/use-json-in-watcher-webhook-body/295349>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [January 25, 2022, 1:21pm UTC](https://discuss.elastic.co/t/use-json-in-watcher-webhook-body/295349 "2022-01-25T13:21:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosaLux161](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@rosaLux161](https://discuss.elastic.co/u/rosaLux161)\
**Post date:** [January 25, 2022, 1:21pm UTC](https://discuss.elastic.co/t/use-json-in-watcher-webhook-body/295349/1 "2022-01-25T13:21:17Z")

</div>

How is it possible to use plain JSON in Watcher webhook body?

Just putting the plain JSON in the body

```auto
{
    [...]
    "actions":{
       "opsgenie":{
          "webhook":{
             "method":"POST",
             "host":"some.api",
             "path":"/somewhere/",
             "port":443,
             "scheme":"https",
             "headers":{
                "Authorization":"Key XXX",
                "Content-Type":"application/json"
             },
             "body": {
                "message":"Some message",
                "key":"value",
                "some_array":[
                    "string a",
                    "string b"
                ]
             }
          }
       }
    }
 }

```

results in interpreting fields by Watcher which fails:

> [1:653] [script] unknown field [message]

Handling the whole JSON as a string does not work to. How to handle it?

Same problem, but no solution: [Watcher webhook body How to build a json format?](https://discuss.elastic.co/t/watcher-webhook-body-how-to-build-a-json-format/231434)

---

<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:** [February 8, 2022, 1:35pm UTC](https://discuss.elastic.co/t/use-json-in-watcher-webhook-body/295349/2 "2022-02-08T13:35:03Z")

</div>

Use the `{{#toJson}}` template function in the `body`.

See [Search templates | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#search-template-convert-json)

---

<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:** [March 8, 2022, 1:35pm UTC](https://discuss.elastic.co/t/use-json-in-watcher-webhook-body/295349/3 "2022-03-08T13:35:36Z")

</div>

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