Schema/Metadata API Reference: Event Triggers

Event triggers are used to capture database changes and send them to a configured webhook.

create_event_trigger

create_event_trigger is used to create a new event trigger or replace an existing event trigger.

POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type" : "create_event_trigger",
    "args" : {
        "name": "sample_trigger",
        "table": "users",
        "webhook": "https://httpbin.org/post",
        "insert": {
            "columns": "*",
            "payload": ["username"]
        },
        "update": {
            "columns": ["username", "real_name"],
            "payload": "*"
        },
        "delete": {
            "columns": "*"
        },
        "headers":[
          {
              "name": "X-Hasura-From-Val",
              "value": "myvalue"
          },
          {
              "name": "X-Hasura-From-Env",
              "value_from_env": "EVENT_WEBHOOK_HEADER"
          }
        ],
        "replace": false
    }
}

Args syntax

Key Required Schema Description
name true TriggerName Name of the event trigger
table true TableName Name of the table
webhook true String Full url of webhook
insert false OperationSpec Specification for insert operation
update false OperationSpec Specification for update operation
delete false OperationSpec Specification for delete operation
headers false [ HeaderFromValue | HeaderFromEnv ] List of headers to be sent with the webhook
replace false Boolean If set to true, event trigger is replaced with the new definition

delete_event_trigger

delete_event_trigger is used to delete an event trigger.

POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type" : "delete_event_trigger",
    "args" : {
        "name": "sample_trigger"
    }
}

Args syntax

Key Required Schema Description
name true TriggerName Name of the event trigger

TriggerName

String

OperationSpec

Key Required Schema Description
columns true EventTriggerColumns List of columns or “*” to listen changes on
payload false EventTriggerColumns List of columns or “*” to send as part of webhook payload

HeaderFromValue

Key required Schema Description
name true String Name of the header
value true String Value of the header

HeaderFromEnv

Key required Schema Description
name true String Name of the header
value_from_env true String Name of the environment variable which holds the value of the header

EventTriggerColumns

"*" | [PGColumn]