# Is there a way to trigger an handler for an event created with the agent API /events?

**URL:** <https://discourse.sensu.io/t/is-there-a-way-to-trigger-an-handler-for-an-event-created-with-the-agent-api-events/1977>\
**Category:** Sensu Go\
**Created:** [July 30, 2020, 10:24am UTC](https://discourse.sensu.io/t/is-there-a-way-to-trigger-an-handler-for-an-event-created-with-the-agent-api-events/1977 "2020-07-30T10:24:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![romainquere](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@romainquere](https://discourse.sensu.io/u/romainquere)\
**Post date:** [July 30, 2020, 10:24am UTC](https://discourse.sensu.io/t/is-there-a-way-to-trigger-an-handler-for-an-event-created-with-the-agent-api-events/1977/1 "2020-07-30T10:24:48Z")

</div>

I generated an event thourgh the agent API on a Windows server.

```
$Uri = 'http://127.0.0.1:3031/events'
$Form= '
{ 
  "check": {
    "metadata": {
      "name": "mysql-backup-job"
    },
    "status": 0,
    "output": "mysql backup ran successfully!"}
}
'
Invoke-WebRequest -Uri $Uri -Method Post -Form $Form

```

As expected, I see this event in the backend but don’t know if there is a way to trigger an handler (my email handler for example) based on this event ?  
I tried to add the handler in the event itself (example below) but it doesn’t seem to be taken into account.

```
$Form= '
{ 
  "check": {
    "metadata": {
      "name": "mysql-backup-job"
    },
	"spec": {
	  "handlers": ["email"]
	},
    "status": 0,
    "output": "mysql backup ran successfully!"}
}
'

```

Thanks by advance for your help.

---

<div class="post-metadata">

**Author:** ![todd](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/todd/32/936_2.png) [@todd](https://discourse.sensu.io/u/todd)\
**Post date:** [July 30, 2020, 11:44am UTC](https://discourse.sensu.io/t/is-there-a-way-to-trigger-an-handler-for-an-event-created-with-the-agent-api-events/1977/2 "2020-07-30T11:44:17Z")

</div>

You’re almost there. For an event, the ‘handlers’ definition does not go under ‘spec’. This should work:

```
{ 
  "check": {
    "metadata": {
      "name": "mysql-backup-job"
    },
    "handlers": ["email"],
    "status": 0,
    "output": "mysql backup ran successfully!"}
}
```

---

<div class="post-metadata">

**Author:** ![romainquere](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@romainquere](https://discourse.sensu.io/u/romainquere)\
**Post date:** [July 30, 2020, 11:57am UTC](https://discourse.sensu.io/t/is-there-a-way-to-trigger-an-handler-for-an-event-created-with-the-agent-api-events/1977/4 "2020-07-30T11:57:01Z")

</div>

You’re right, it’s working as expected.  
Thx a lot
