# Want to loop post text into MS team Channel but Error

**URL:** <https://discuss.elastic.co/t/want-to-loop-post-text-into-ms-team-channel-but-error/343129>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-monitoring, painless\
**Created:** [September 15, 2023, 10:24am UTC](https://discuss.elastic.co/t/want-to-loop-post-text-into-ms-team-channel-but-error/343129 "2023-09-15T10:24:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rathasatekun](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@rathasatekun](https://discuss.elastic.co/u/rathasatekun)\
**Post date:** [September 15, 2023, 10:24am UTC](https://discuss.elastic.co/t/want-to-loop-post-text-into-ms-team-channel-but-error/343129/1 "2023-09-15T10:24:48Z")

</div>

Hi Elastic team I have watcher data from search from indices and then make text for post into ms team channel but i can not send text value into ms team channel it's error: "Newtonsoft.Json.JsonReaderException: After parsing a value an unexpected character was encountered: T. Path 'text', line 2, position 23."

this Watch JSON

```auto
{
  "trigger": {
    "schedule": {
      "daily": {
        "at": [
          "06:00"
        ]
      }
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "xxxx-storehealth-log*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "query": {
            "bool": {
              "must": [
                {
                  "query_string": {
                    "query": """
                            TERMINAL_TYPE.keyword : "POS" and STORE_ID : * and PARTITION_SPACE_GB.DRIVE.keyword : "C:" and PARTITION_SPACE_GB.SPACE <2 """
                  }
                }
              ],
              "filter": {
                "range": {
                  "@timestamp": {
                    "time_zone": "+07:00",
                    "gte": "now/d-7d",
                    "lt": "now/m-60m"
                  }
                }
              }
            }
          },
          "aggs": {
            "xxxx": {
              "multi_terms": {
                "terms": [
                  {
                    "field": "STORE_ID.keyword"
                  },
                  {
                    "field": "TERMINAL_NO.keyword"
                  },
                  {
                    "field": "TERMINAL_TYPE.keyword"
                  },
                  {
                    "field": "TERMINAL_NAME.keyword"
                  }
                ],
                "size": 10
              }
            }
          },
          "_source": [
            "STORE_ID",
            "TERMINAL_NO",
            "TERMINAL_TYPE",
            "TERMINAL_NAME",
            "@timestamp"
          ]
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 0
      }
    }
  },
  "actions": {
    "MS_Teams": {
      "transform": {
        "script": {
          "source": """
                    ctx.payload.xxxx = ctx.payload.aggregations.xxxx.buckets.stream().map(p -> 
                   '{"TERMINAL_NAME": "'+p.key[3]+'"}'
                   ).collect(Collectors.toList())
                  """,
          "lang": "painless"
        }
      },
      "foreach": "ctx.payload.xxxx",
      "max_iterations": 100,
      "webhook": {
        "scheme": "https",
        "host": "xxxx.webhook.office.com",
        "port": 443,
        "method": "post",
        "path": "/webhookb2/xxxx",
        "params": {},
        "headers": {
          "Content-Type": "application/json"
        },
          "body": """{ "text": " ==========1
The watcher:*{{ctx.payload}}* in env:*{{ctx.payload}}* found that the process *{{ctx.payload}}* has been utilizing CPU over 95% for the past 1 hr on node:
{{#ctx.payload.nodes}}	{{.}}

{{/ctx.payload.nodes}}

The runbook entry is here: *{{ctx.payload}}* "}"""
      }
    }
  },
  "metadata": {
    "service": {
      "name": "xxxxxxxx"
    }
  }
}

```

---

<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:** [October 13, 2023, 10:24am UTC](https://discuss.elastic.co/t/want-to-loop-post-text-into-ms-team-channel-but-error/343129/2 "2023-10-13T10:24:53Z")

</div>

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