# Need to send json in watcher webhook

**URL:** <https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [June 13, 2016, 6:08pm UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646 "2016-06-13T18:08:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticbharat](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@elasticbharat](https://discuss.elastic.co/u/elasticbharat)\
**Post date:** [June 13, 2016, 6:08pm UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646/1 "2016-06-13T18:08:56Z")

</div>

I want to send json data in body of watcher webhook. I am defining action like below

my json body should be like {'watcher\_id':24}

The following action is returning 404 error.

"actions" : {  
"my\_webhook" : {  
"webhook" : {  
"method" : "POST",  
"host" : "10.225.117.135",  
"port" : 8001,  
"path": "/gen/api/v1/watch",  
"headers" : {  
"Authorization" : "Bearer ROOM\_TOKEN",  
"Content-Type": "application/json"  
},  
"body" : "watcher\_id: {{ctx.payload.hits.total}}"  
}  
}  
}

Please suggest correct way of sending json in webhook body.

---

<div class="post-metadata">

**Author:** ![elasticbharat](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@elasticbharat](https://discuss.elastic.co/u/elasticbharat)\
**Post date:** [June 13, 2016, 6:53pm UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646/2 "2016-06-13T18:53:24Z")

</div>

Detailed info:  
Errors + logs from my application goes to logstash in JSON format. From Logstash, the messages are stored in elasticsearch. I am running watcher on elastic search. If the condition "watcher\_id" is "test", then action can be triggered at 10second interval. The action is webhook. I want to send json data in webhook to remote Django rest server. As per the below configuration, the rest request goes to django rest server goes. But Django rest server returns back 404 error to the watcher. I could see this in output of watcher records. Sample output is given in output part(2)

Even though I gave header as json in action, the django rest server interpreted as text/html. The django rest server has model defined with watcher\_id as primary field. There is no error in django rest server. I could admin GUI and post data in django admin GUI.

I tried different combinations for body field to send in json from watcher webhook action. But nothing is successful.

output part (1)  
{  
"trigger": {  
"schedule": {  
"interval": "10s"  
}  
},  
"input": {  
"search": {  
"request": {  
"indices": [  
"mysecond"  
],  
"body": {  
"query": {  
"match": {  
"watcher\_id": "test"  
}  
}  
}  
}  
}  
},  
"condition": {  
"compare": {  
"ctx.payload.hits.total": {  
"gt": 0  
}  
}  
},  
"actions": {  
"my\_webhook": {  
"webhook": {  
"method": "POST",  
"host": "10.225.117.135",  
"port": 8001,  
"path": "/gen/api/v1/watch",  
"headers": {  
"Authorization": "Bearer ROOM\_TOKEN",  
"Content-Type": "application/json"  
},  
"body": "watcher\_id: {{ctx.payload.hits.total}}"  
}  
}  
}  
}

output part (2)  
"actions": [  
{  
"id": "my\_webhook",  
"type": "webhook",  
"status": "failure",  
"reason": "received [404] status code",  
"webhook": {  
"request": {  
"host": "10.225.117.135",  
"port": 8001,  
"scheme": "http",  
"method": "post",  
"path": "/gen/api/v1/watch",  
"headers": {  
"Authorization": "Bearer ROOM\_TOKEN",  
"Content-Type": "application/json"  
},  
"body": "watcher\_id: 940"  
},  
"response": {  
"status": 404,  
"headers": {  
"content-type": [  
"text/html"  
],  
"server": [  
"WSGIServer/0.1 Python/2.7.6"  
],  
"date": [  
"Mon, 13 Jun 2016 17:50:36 GMT"  
],  
"vary": [  
"Cookie"  
]  
}  
}  
}  
}  
]

---

<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:** [June 14, 2016, 7:56am UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646/3 "2016-06-14T07:56:29Z")

</div>

Hey,

as already stated in another thread, please use proper formatting, otherwise helping is hard.

The error 404 is returned by your webserver and means the resource/HTTP endpoint (`/gen/api/v1/watch`) does not exist, which can happen, but it also means that this is not a watcher issue. You should check if the endpoint is reachable using curl (or another HTTP client of your choice) and the parameters from the watch.

--Alex

---

<div class="post-metadata">

**Author:** ![Pransh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pransh/32/12806_2.png) [@Pransh](https://discuss.elastic.co/u/Pransh)\
**Post date:** [September 21, 2016, 10:36am UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646/4 "2016-09-21T10:36:41Z")

</div>

@spinscale Hi

I want to send the complete payload as a JSON output via webhook, is it possible?

Please let me know

Regards

---

<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:** [September 21, 2016, 11:10am UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646/5 "2016-09-21T11:10:05Z")

</div>

Hey,

please open new topics if you have a question instead of reopening months old topics. Also one message is enough.

What you are searching for has been released with Elasticsearch 2.4.0. It is the `#{{toJson}}` helper, see [https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-template.html#\_converting\_parameters\_to\_json](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-template.html#_converting_parameters_to_json)

--Alex

---

<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:** [July 6, 2017, 1:42pm UTC](https://discuss.elastic.co/t/need-to-send-json-in-watcher-webhook/52646/6 "2017-07-06T13:42:48Z")

</div>


