# How to use Elasticsearch delete\_by\_query API's in watcher webhook. Its failing on Authentication

**URL:** https://discuss.elastic.co/t/how-to-use-elasticsearch-delete-by-query-apis-in-watcher-webhook-its-failing-on-authentication/334415
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [May 26, 2023, 9:57am UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-delete-by-query-apis-in-watcher-webhook-its-failing-on-authentication/334415 "2023-05-26T09:57:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Disha\_Bodade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/disha_bodade/32/84522_2.png) [@Disha\_Bodade](https://discuss.elastic.co/u/Disha_Bodade)
#### Post date: [May 26, 2023, 9:57am UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-delete-by-query-apis-in-watcher-webhook-its-failing-on-authentication/334415/1 "2023-05-26T09:57:05Z")

</div>

Hi Team,  
I am using delete\_by\_query in elasticsearch watcher action as webhook as below.

```auto
"actions": {
    "my_api": {
      "webhook": {
        "scheme": "https",
        "host": "130.8.1.198",
        "port": 9200,
        "method": "POST",
        "path": "/search-my-index-*/_delete_by_query",
        "body": """{"query": {"terms":{ "url":[{{ctx.payload._value}}] }}}"""
        "headers": {
              "Authenticate": "Bearer Zwabdhrifssr45kedhlgnhrbdlkg"
      }
    }
  }
  }

```

But when executing it shows below error

```auto
"body": "{\"error\":{\"root_cause\":[{\"type\":\"security_exception\",\"reason\":\"missing authentication credentials for REST request [/search-my-index-*/_delete_by_query]\",\"header\":{\"WWW-Authenticate\":[\"Basic realm=\\\"security\\\" charset=\\\"UTF-8\\\"\",\"Bearer realm=\\\"security\\\"\",\"ApiKey\"]}}],\"type\":\"security_exception\",\"reason\":\"missing authentication credentials for REST request [/search-my-index-*/_delete_by_query]\",\"header\":{\"WWW-Authenticate\":[\"Basic realm=\\\"security\\\" charset=\\\"UTF-8\\\"\",\"Bearer realm=\\\"security\\\"\",\"ApiKey\"]}},\"status\":401}"
          }

```

Note: The index is created using elastic web crawler.

Please let me know, watcher doesn't work like devtool? do we need to give username and password?

---

<div class="post-metadata">

### Author: ![Priscilla\_Parodi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priscilla_parodi/32/43047_2.png) [@Priscilla\_Parodi](https://discuss.elastic.co/u/Priscilla_Parodi)
#### Post date: [May 29, 2023, 10:16pm UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-delete-by-query-apis-in-watcher-webhook-its-failing-on-authentication/334415/2 "2023-05-29T22:16:41Z")

</div>

Hello @Disha_Bodade,

The `auth` attribute in the webhook action is not required, as you can [read here](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/actions-webhook.html#webhook-action-attributes), but if it makes sense, basic authentication is supported.

Make sure that "require authentication" is not enabled. If it is, you must provide a username and password for login-type authentication.

 ![IMG_1304](https://us1.discourse-cdn.com/elastic/original/3X/0/9/09d14eaa05e32b6b9f57bde8899f3dd5c6bfc681.png)

Note: I noticed that there is a missing comma (",") after the "body" field. Please try to correct that as well and resend the request.

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: [June 26, 2023, 10:17pm UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-delete-by-query-apis-in-watcher-webhook-its-failing-on-authentication/334415/3 "2023-06-26T22:17:12Z")

</div>

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