Skip to main content
Version: v2.x

Metadata API Reference: Event Triggers

Introduction

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

Supported from

The metadata API is supported for versions v2.0.0 and above and replaces the older schema/metadata API.

pg_create_event_trigger

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

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

{
"type" : "pg_create_event_trigger",
"args" : {
"name": "sample_trigger",
"table": {
"name": "users",
"schema": "public"
},
"source": "default",
"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"
}
],
"cleanup_config": {
"schedule": "0 0 * * *",
"batch_size": 10000,
"clear_older_than": 168,
"timeout": 60,
"clean_invocation_logs": false,
"paused": false
},
"replace": false
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the event trigger
tabletrueQualifiedTableObject with table name and schema
sourcefalseSourceNameName of the source database of the table (default: default)
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
request_transformfalseRequestTransformationAttaches a Request Transformation to the Event Trigger.
response_transformfalseResponseTransformationAttaches a Request Transformation to the Event Trigger.
cleanup_configfalseAutoEventTriggerCleanupConfigCleanup config for the auto cleanup process (EE/Cloud only).

(*) Either webhook or webhook_from_env are required.

pg_delete_event_trigger

pg_delete_event_trigger is used to delete an event trigger.

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

{
"type" : "pg_delete_event_trigger",
"args" : {
"name": "sample_trigger",
"source": "default"
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the event trigger
sourcefalseSourceNameName of the source database of the trigger (default: default)

pg_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/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

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

Args syntax

KeyRequiredSchemaDescription
event_idtrueStringUUID of the event

pg_invoke_event_trigger

invoke_event_trigger is used to invoke an event trigger with custom payload.

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

{
"type" : "pg_invoke_event_trigger",
"args" : {
"name": "sample_trigger",
"source": "default",
"payload": {}
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the event trigger
payloadtrueJSONSome JSON payload to send to trigger
sourcefalseSourceNameName of the source database of the trigger (default: default)

mssql_create_event_trigger

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

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

{
"type" : "mssql_create_event_trigger",
"args" : {
"name": "sample_trigger",
"table": {
"name": "users",
"schema": "public"
},
"source": "default",
"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"
}
],
"cleanup_config": {
"schedule": "0 0 * * *",
"batch_size": 10000,
"clear_older_than": 168,
"timeout": 60,
"clean_invocation_logs": false,
"paused": false
},
"replace": false
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the event trigger
tabletrueQualifiedTableObject with table name and schema
sourcefalseSourceNameName of the source database of the table (default: default)
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
request_transformfalseRequestTransformationAttaches a Request Transformation to the Event Trigger.
response_transformfalseResponseTransformationAttaches a Request Transformation to the Event Trigger.
cleanup_configfalseAutoEventTriggerCleanupConfigCleanup config for the auto cleanup process (EE/Cloud only).

(*) Either webhook or webhook_from_env are required.

mssql_delete_event_trigger

mssql_delete_event_trigger is used to delete an event trigger.

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

{
"type" : "mssql_delete_event_trigger",
"args" : {
"name": "sample_trigger",
"source": "default"
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the event trigger
sourcefalseSourceNameName of the source database of the trigger (default: default)

mssql_redeliver_event

mssql_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/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

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

Args syntax

KeyRequiredSchemaDescription
event_idtrueStringUUID of the event

mssql_invoke_event_trigger

invoke_event_trigger is used to invoke an event trigger with custom payload.

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

{
"type" : "mssql_invoke_event_trigger",
"args" : {
"name": "sample_trigger",
"source": "default",
"payload": {}
}
}

Args syntax

KeyRequiredSchemaDescription
nametrueTriggerNameName of the event trigger
payloadtrueJSONSome JSON payload to send to trigger
sourcefalseSourceNameName of the source database of the trigger (default: default)

cleanup_event_trigger_logs

Available on: Enterprise Edition/Cloud

cleanup_event_trigger_logs is used to manually delete the event logs for a given event trigger.

POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type" : "cleanup_event_trigger_logs",
"args": {
"event_trigger_name": "sample_trigger",
"source": "default",
"batch_size": 10000,
"clear_older_than": 168,
"timeout": 60,
"clean_invocation_logs": false
}
}

Args syntax

KeyRequiredSchemaDescription
event_trigger_nametrueStringName of the event trigger whose logs needs to be cleaned up
sourcefalseSourceNameSource to which the event trigger belong. Default default
batch_sizefalseIntMaximum number of logs to delete in a single statement during the cleanup action. If there are more events to be cleaned than the batch_size then the cleanup action will execute multiple statements sequentially until all old event logs are cleared. Default 10000
clear_older_thantrueIntEvent logs retention period (in hours).
timeoutfalseIntMaximum time (in seconds) that a batch can take during the cleanup process. If a batch times out, the cleanup process is halted. Default: 60
clean_invocation_logsfalseBooleanShould corresponding invocation logs be cleaned. Default false

resume_event_trigger_cleanups

Available on: Enterprise Edition/Cloud

resume_event_trigger_cleanups is used to resume the paused log cleaner for event triggers.

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

{
"type": "resume_event_trigger_cleanups",
"args": {
"event_triggers": [
{
"source_name": "default",
"event_triggers": ["sample_trigger"]
}
]
}
}

Args syntax

KeyRequiredSchemaDescription
event_triggerstrueTriggerLogCleanupSources | [EventTriggerQualifier]Event triggers for which to start the cleanup process

pause_event_trigger_cleanups

Available on: Enterprise Edition/Cloud
- `pause_event_trigger_cleanups` is used to pause the log cleaner for event triggers which already have a cleaner installed.
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
"type": "pause_event_trigger_cleanups",
"args": {
"event_triggers": [
{
"source_name": "default",
"event_triggers": ["sample_trigger"]
}
]
}
}

Args syntax

KeyRequiredSchemaDescription
event_triggerstrueTriggerLogCleanupSources | [EventTriggerQualifier]Event triggers for which to pause the cleanup process
Note

The start and pause APIs for event trigger cleanup work only for event triggers that have a cleanup configuration defined.