Watcher: Invalid JSON

I am trying to create the following watcher and seeing Invalid JSON error message and not able to create the watcher.

{
  "trigger": {
    "schedule": {
      "interval": "200m"
    }
  },
  "input": {
    "search": {
      "request": {
        "body": {
          "size": 0,
          "query": {
            "match_all": {}
          }
        },
        "indices": [
          "*"
        ]
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 10
      }
    }
  },
 "actions" : {
  "create_github_issue" : {
    "webhook" : {
      "method" : "POST",
      "url" : "https://api.github.com/repos/<owner>/<repo>/issues",
      "body" : "{
        \"title\": \"Found errors in 'contact.html'\",
        \"body\": \"Found {{ctx.payload.hits.total}} errors in the last 5 minutes\",
        \"assignee\": \"web-admin\",
        \"labels\": [ \"bug\", \"sev2\" ]
      }",
      "auth" : {
        "basic" : {
          "username" : "username", 
          "password" : "password"
        }
      }
    }
  }
}
}

The full exception would be tremendously useful in this case instead of just the error mesasge.

Two things

  • First it looks as if there is an additional closing bracket at the end
  • Second, the body field needs to be in a single line, JSON does not support multi line elements.

hope this helps, otherwise please provide more information.

Thanks.

--Alex

1 Like

Thanks Alex for your quick response. It was the second one which was causing the issue.
May be the example in this link https://www.elastic.co/guide/en/x-pack/current/actions-webhook.html
needs to be updated to have the body in single line. Have referred the example from here.

Check your json file from here https://jsonformatter.curiousconcept.com/

indeed, that's a documentation issue, that I just fixed.

Thanks a lot for pointing it out!

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