# Transform script via Create Watcher API

**URL:** <https://discuss.elastic.co/t/transform-script-via-create-watcher-api/342608>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [September 8, 2023, 12:57pm UTC](https://discuss.elastic.co/t/transform-script-via-create-watcher-api/342608 "2023-09-08T12:57:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddoroshenko](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@ddoroshenko](https://discuss.elastic.co/u/ddoroshenko)\
**Post date:** [September 8, 2023, 12:57pm UTC](https://discuss.elastic.co/t/transform-script-via-create-watcher-api/342608/1 "2023-09-08T12:57:06Z")

</div>

Hi!

I'm trying to put new watcher via Create Watcher API

```auto
curl -X PUT "localhost:9200/_watcher/watch/my-watch?pretty" -H 'Content-Type: application/json' -d'
{
...
  "actions" {
    "problem": {
      "transform": {
        "script": "return ['webhook_body': webhook_body]"
      }
    }
  }
...
}
'

```

I get the response

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "return [ webhook_body : webhook_bo ...",
          " ^---- HERE"
        ],
        "script" : "return [webhook_body : webhook_body]",
        "lang" : "painless",
        "position" : {
          "offset" : 9,
          "start" : 0,
          "end" : 34
        }
      }
    ],
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [
      "return [ webhook_body : webhook_bo ...",
      " ^---- HERE"
    ],
    "script" : "return [webhook_body : webhook_body]",
    "lang" : "painless",
    "position" : {
      "offset" : 9,
      "start" : 0,
      "end" : 34
    },
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "cannot resolve symbol [webhook_body]"
    }
  },
  "status" : 400
}

```

What coud be a problem?

And the main question - How can I put watcher with multiline transform scripts via API?

---

<div class="post-metadata">

**Author:** ![ddoroshenko](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@ddoroshenko](https://discuss.elastic.co/u/ddoroshenko)\
**Post date:** [September 11, 2023, 12:07pm UTC](https://discuss.elastic.co/t/transform-script-via-create-watcher-api/342608/2 "2023-09-11T12:07:39Z")

</div>

Well

after changing quotes to unicode characters it works

```auto
[\u0027webhook_body\u0027 : webhook_body]

```

---

<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 9, 2023, 12:08pm UTC](https://discuss.elastic.co/t/transform-script-via-create-watcher-api/342608/3 "2023-10-09T12:08:36Z")

</div>

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