Skip to main content
Version: v2.x

Schema/Metadata API Reference: Event Triggers (Deprecated)

Deprecation

In versions v2.0.0 and above, the schema/Metadata API is deprecated in favour of the schema API and the Metadata API.

Though for backwards compatibility, the schema/Metadata APIs will continue to function.

Introduction

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": {
"name": "users",
"schema": "public"
},
"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

KeyRequiredSchemaDescription
nametrueTriggerNameName of the Event Trigger
tabletrueQualifiedTableObject with table name and schema
webhookfalseStringFull url of webhook (*)
webhook_from_envfalseStringEnvironment variable name of webhook (must exist at boot time) (*)
insertfalseOperationSpecSpecification for insert operation
updatefalseOperationSpecSpecification for update operation
deletefalseOperationSpecSpecification for delete operation
headersfalse[ HeaderFromValue | HeaderFromEnv ]List of headers to be sent with the webhook
retry_conffalseRetryConfRetry configuration if event delivery fails
replacefalseBooleanIf set to true, the Event Trigger is replaced with the new definition
enable_manualfalseBooleanIf set to true, the Event Trigger can be invoked manually

(*) Either webhook or webhook_from_env are required.

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

KeyRequiredSchemaDescription
nametrueTriggerNameName of the Event Trigger

redeliver_event

redeliver_event is used to redeliver an existing event. For example, if an event is marked as error ( say it did not succeed after retries), you can redeliver it using this API. Note that this will reset the count of retries so far. If the event fails to deliver, it will be retried automatically according to its retry_conf.

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

{
"type" : "redeliver_event",
"args" : {
"event_id": "ad4f698f-a14e-4a6d-a01b-38cd252dd8bf"
}
}

Args syntax

KeyRequiredSchemaDescription
event_idtrueStringUUID of the event

invoke_event_trigger

invoke_event_trigger is used to invoke an Event Trigger with custom payload.

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

{
"type" : "invoke_event_trigger",
"args" : {
"name": "sample_trigger",
"payload": {}
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the Event Trigger
payloadtrueJSONSome JSON payload to send to trigger