# Advanced Watcher: Use key value in a mail webhook

**URL:** https://discuss.elastic.co/t/advanced-watcher-use-key-value-in-a-mail-webhook/299457
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [March 11, 2022, 1:30pm UTC](https://discuss.elastic.co/t/advanced-watcher-use-key-value-in-a-mail-webhook/299457 "2022-03-11T13:30:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jonathan\_Fernandez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonathan_fernandez/32/102934_2.png) [@Jonathan\_Fernandez](https://discuss.elastic.co/u/Jonathan_Fernandez)
#### Post date: [March 11, 2022, 1:30pm UTC](https://discuss.elastic.co/t/advanced-watcher-use-key-value-in-a-mail-webhook/299457/1 "2022-03-11T13:30:45Z")

</div>

Hello everybody!

So, basically I'm trying to get my 'key' value to print it into my mail body, but I'm not being able to do it. Once I get it, I will iterate over the buckets with a "foreach" before the webhook (within the "action" data).

This is the path (it works until I reach the key): {{ctx.payload.aggregations.service.buckets.key}}

I also used this way: {{ctx.payload.aggregations.service.buckets[0].key}}

And this is the "result" output (data is dynamic):

```auto
"result": {
    "execution_time": "2022-03-11T13:25:33.552Z",
    "execution_duration": 17,
    "input": {
      "type": "search",
      "status": "success",
      "payload": {
        "_shards": {
          "total": 30,
          "failed": 0,
          "successful": 30,
          "skipped": 28
        },
        "hits": {
          "hits": [],
          "total": 83,
          "max_score": null
        },
        "took": 14,
        "timed_out": false,
        "aggregations": {
          "service": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
              {
                "doc_count": 50,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 42,
                      "key": "createDocument"
                    },
                    {
                      "doc_count": 6,
                      "key": "createInvoiceDocument"
                    },
                    {
                      "doc_count": 2,
                      "key": "createClaimNotificationDocument"
                    }
                  ]
                },
                "key": "ClaimAPIPortType"
              },
              {
                "doc_count": 11,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 4,
                      "key": "manageRoles"
                    },
                    {
                      "doc_count": 3,
                      "key": "getRolesToObject"
                    },
                    {
                      "doc_count": 2,
                      "key": "getInfoToParty"
                    },
                    {
                      "doc_count": 2,
                      "key": "manageAccounts"
                    }
                  ]
                },
                "key": "PartyInterface-v4_0"
              },
              {
                "doc_count": 7,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 7,
                      "key": "updatePaymentStatus"
                    }
                  ]
                },
                "key": "SumexPaymentUpdateService"
              },
              {
                "doc_count": 6,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 6,
                      "key": "invoiceDetails"
                    }
                  ]
                },
                "key": "InvoiceDetails"
              },
              {
                "doc_count": 6,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 6,
                      "key": "geocode"
                    }
                  ]
                },
                "key": "MapsInterface-v1_0"
              },
              {
                "doc_count": 1,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 1,
                      "key": "sendChat"
                    }
                  ]
                },
                "key": "AIDInterface-v1_0"
              },
              {
                "doc_count": 1,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 1,
                      "key": "statusUpdate"
                    }
                  ]
                },
                "key": "ClaimPaymentService"
              },
              {
                "doc_count": 1,
                "operation": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                    {
                      "doc_count": 1,
                      "key": "preview"
                    }
                  ]
                },
                "key": "CommunicationService-v1_0"
              }
            ]
          }
        }
      },

```

Could you please give a hand with this?

Thank you! 😃

---

<div class="post-metadata">

### Author: ![Jonathan\_Fernandez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonathan_fernandez/32/102934_2.png) [@Jonathan\_Fernandez](https://discuss.elastic.co/u/Jonathan_Fernandez)
#### Post date: [March 17, 2022, 7:08am UTC](https://discuss.elastic.co/t/advanced-watcher-use-key-value-in-a-mail-webhook/299457/2 "2022-03-17T07:08:05Z")

</div>

The problem was solved by applying a segment as follows:  
{{#ctx._your\_segment\_here_}} {{key}} {{/ctx._your\_segment\_here_}}

---

<div class="post-metadata">

### Author: ![matschaffer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matschaffer/32/95396_2.png) [@matschaffer](https://discuss.elastic.co/u/matschaffer)
#### Post date: [April 4, 2022, 6:50am UTC](https://discuss.elastic.co/t/advanced-watcher-use-key-value-in-a-mail-webhook/299457/3 "2022-04-04T06:50:03Z")

</div>

Awesome work finding it @Jonathan_Fernandez !

---

<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: [May 2, 2022, 6:50am UTC](https://discuss.elastic.co/t/advanced-watcher-use-key-value-in-a-mail-webhook/299457/4 "2022-05-02T06:50:22Z")

</div>

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