# X-pack watch: error while sending mail with PDF attachment

**URL:** <https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640>\
**Category:** Elasticsearch\
**Created:** [June 23, 2017, 12:53pm UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640 "2017-06-23T12:53:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiranilla](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kiranilla](https://discuss.elastic.co/u/kiranilla)\
**Post date:** [June 23, 2017, 12:53pm UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/1 "2017-06-23T12:53:17Z")

</div>

I have configured the watch for an index and saved successfully .  
Below is the code snippet for actions{...} section only.

```
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "attachments": {
          "dashboard.pdf": {
            "http": {
              "request": {
                "scheme": "http",
                "host": "localhost",
                "port": 5601,
                "method": "get",
                "path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
                "params": {},
                "headers": {}
              },
              "content_type": "application/pdf"
            }
          }
        },
        "priority": "high",
        "to": [
          "kiran.ku.ila@act.com"
        ],
        "subject": "Watcher Report on closed tickets",
        "body": {
          "text": " Watcher \"{{ctx.watch_id}}\" Encountered {{ctx.payload.hits.total}} log entries, see attached data"
        }
      }
    }
  }

```

when the trigger is executed on a specified time interval, this actions block is executed and trying to send a mail attaching the PDF, but it is failing with the below mentioned error:

```
 "reason": "Watch[_inlined_] attachment[dashboard.pdf] HTTP error status host[localhost], port[5601], method[GET], path[/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu], status[401]"

```

I tried modifying the code for authenticating and to attach the PDF in the mail to send.  
As shown below which is in **bold lettering** :

"actions": {  
"send\_email": {  
"email": {  
"profile": "standard",  
"attachments": {  
"dashboard.pdf": {  
"http": {  
"request": {  
"scheme": "http",  
"host": "localhost",  
"port": 5601,  
"method": "get",  
"path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",  
"params": {},  
"headers": {}  
},  
"content\_type": "application/pdf",  
**"auth": {**  
**"basic":{**  
**"username":"elastic",**  
**"password":"** \ ***"**  
**}**  
**}**  
}  
}  
},  
"priority": "high",  
"to": [  
"kiran.ku.ila@act.com"  
],  
"subject": "Watcher Report on closed tickets",  
"body": {  
"text": " Watcher "{{ctx.watch\_id}}" Encountered {{ctx.payload.hits.total}} log entries, see attached data"  
}  
}  
}

but i have ended up with an error :  
`Watcher: [parse_exception] Unknown field name [auth] in http request attachment configuration`

Could you please help me out where should i place the authentication tag ("auth" tag) so that i can successfully run and send the mail with attachment.

---

<div class="post-metadata">

**Author:** ![kiranilla](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kiranilla](https://discuss.elastic.co/u/kiranilla)\
**Post date:** [June 23, 2017, 1:15pm UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/2 "2017-06-23T13:15:04Z")

</div>

I have resolved this issue, by modifying the script as shown below:  
where i have added the "auth" code just below "headers".

```
"request": {
                "scheme": "http",
                "host": "localhost",
                "port": 5601,
                "method": "get",
                "path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
                "params": {},
                "headers": {},
                "auth": {
                  "basic": {
                    "username": "elastic"
					"password": " ****"
                  }
                }
              },
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 23, 2017, 1:42pm UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/3 "2017-06-23T13:42:38Z")

</div>

Hey,

glad you sorted it out! Should we improve our documentation somewhere, so people dont fall into this trap or did you maybe even found some wrong documentation that requires fixing?

In addition, you dont need to specify empty `params` and `headers`. Also you can just specify a single `url` field like this, instead of `scheme`, `host`, `port`, `path` and `method`:

```auto
"url" : "http://localhost:5601/api/report..."

```

--Alex

---

<div class="post-metadata">

**Author:** ![kiranilla](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kiranilla](https://discuss.elastic.co/u/kiranilla)\
**Post date:** [June 27, 2017, 12:38pm UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/4 "2017-06-27T12:38:55Z")

</div>

HI Alex,

As you said i have tried the above with single `url` option (which was documented in [www.elastic.co](http://www.elastic.co)), it was giving an error so tired with `host, port, path and method` options.. it worked for me.. not sure exactly.. **but i suspect there was an issue with the json structure or expecting any additional field which was missing when we use `** url **` option.**  
some times i used to get 405 or 404 with exceptions :  
watch[jira] reporting[error\_report.pdf] Error response when trying to trigger reporting generation host[localhost], port[5601] method[POST], path[/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu], status[404]"

when i tried with replacing the url code with `host, port ,path and method` it was able to get the report successfully.

probably you can try it once from your end..  
Thank you.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 28, 2017, 6:26am UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/5 "2017-06-28T06:26:04Z")

</div>

Hey,

if you can share the snippet of your reporting section, that would be great!

--Alex

---

<div class="post-metadata">

**Author:** ![kiranilla](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kiranilla](https://discuss.elastic.co/u/kiranilla)\
**Post date:** [June 28, 2017, 8:29am UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/6 "2017-06-28T08:29:47Z")

</div>

Hi Alex,

The below is the code snippet..:  
The below `path` : is the downloaded URL path for pdf

```
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "attachments": {
          "dashboard.pdf": {
            "http": {
              "request": {
                "scheme": "http",
                "host": "localhost",
                "port": 5601,
                "method": "get",
                "path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
                "params": {},
                "headers": {},
                "auth": {
                  "basic": {
                    "username": "elastic",
					"password": " ****"
                  }
                }
              },
              "content_type": "application/pdf"
            }
          }
        },
        "priority": "high",
        "to": [
          "kiran.i@acc.com"
        ],
        "subject": "Watcher Report on closed tickets",
        "body": {
          "text": " Watcher \"{{ctx.watch_id}}\" Encountered {{ctx.payload.hits.total}} log entries, see attached data"
        }
      }
    }
  }
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 28, 2017, 8:51am UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/7 "2017-06-28T08:51:52Z")

</div>

also the snippet where it does not work would be useful for comparison. I'm of course more interested in the case, that does not work.

And the output of the execute watch api or a watch history record in the bad case would be nice as well (note, you might want to redact things out there, like IP addresses).

--Alex

---

<div class="post-metadata">

**Author:** ![kiranilla](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kiranilla](https://discuss.elastic.co/u/kiranilla)\
**Post date:** [June 28, 2017, 9:58am UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/8 "2017-06-28T09:58:31Z")

</div>

The below code ..which is not working and throwing an exception when running:

```
  "actions": {
    "my-logging-action": {
      "logging": {
        "level": "info",
        "text": "There are {{ctx.payload.hits.total}} documents in your index. Threshold is 3."
      }
    },
    "send_email": {
      "email": {
        "profile": "standard",
        "priority": "high",
        "to": [
          "kiran.i@acc.com"
        ],
        "subject": "Encountered {{ctx.payload.hits.total}} errors",
        "body": {
          "text": "Too many error in the system, see attached data"
        },
		"attachments" : {
			"dashboard.pdf" : {
				"reporting" : {
					"url": "http://localhost:5601/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu"
				}
			}
		}
      }
    }
  }
```

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raj_kumar/32/25420_2.png) [@Raj\_Kumar](https://discuss.elastic.co/u/Raj_Kumar)\
**Post date:** [June 30, 2017, 3:55pm UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/9 "2017-06-30T15:55:28Z")

</div>

Hi kIran,

In this case,let say am scheduling every month automatically,can we use the same path or each every time we should change the path and replace the existing path

("path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",)

Thanks,  
Raj

---

<div class="post-metadata">

**Author:** ![kiranilla](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kiranilla](https://discuss.elastic.co/u/kiranilla)\
**Post date:** [July 5, 2017, 9:27am UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/10 "2017-07-05T09:27:09Z")

</div>

In this case we are mailing the PDF which was downloaded earlier,so need to change the path for the latest file which is downloaded

---

<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:** [August 2, 2017, 9:27am UTC](https://discuss.elastic.co/t/x-pack-watch-error-while-sending-mail-with-pdf-attachment/90640/11 "2017-08-02T09:27:19Z")

</div>

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