2020-01-14 15:57:45 +03:00
.. meta ::
:description: Event trigger payload in Hasura
:keywords: hasura, docs, event trigger, payload
2020-03-11 22:42:36 +03:00
.. _trigger_payload:
2018-09-11 14:11:24 +03:00
Event trigger payload
=====================
2018-12-03 15:12:24 +03:00
.. contents :: Table of contents
:backlinks: none
:depth: 1
:local:
2018-09-11 14:11:24 +03:00
The following is the payload and delivery mechanism of an event to the webhook when an event trigger is invoked.
HTTP request method
-------------------
Delivered over `` HTTP POST `` with the following headers:
.. code-block :: none
Content-Type: application/json
JSON payload
------------
.. code-block :: none
{
"event": {
2019-01-28 09:12:52 +03:00
"session_variables": <session-variables>,
2018-09-11 14:11:24 +03:00
"op": "<op-name>",
"data": {
2019-01-28 09:12:52 +03:00
"old": <column-values>,
"new": <column-values>
2018-09-11 14:11:24 +03:00
}
},
"created_at": "<timestamp>",
"id": "<uuid>",
"trigger": {
2019-03-25 20:10:52 +03:00
"name": "<name-of-trigger>"
2018-09-11 14:11:24 +03:00
},
"table": {
"schema": "<schema-name>",
"name": "<table-name>"
}
}
.. list-table ::
:header-rows: 1
* - Key
- Type
- Description
2019-01-28 09:12:52 +03:00
* - session-variables
- Object_ or NULL
2019-09-11 10:17:14 +03:00
- Key-value pairs of session variables (i.e. "x-hasura-\*" variables) and their values (NULL if no session variables found)
2018-09-11 14:11:24 +03:00
* - op-name
- OpName_
2019-05-13 12:41:07 +03:00
- Name of the operation. Can only be "INSERT", "UPDATE", "DELETE", "MANUAL"
2018-09-11 14:11:24 +03:00
* - column-values
- Object_
- Key-value pairs of column name and their values of the table
* - timestamp
- String
2019-03-25 20:10:52 +03:00
- Timestamp at which event was created
2018-09-11 14:11:24 +03:00
* - uuid
- String
2019-03-25 20:10:52 +03:00
- UUID identifier for the event
2018-09-11 14:11:24 +03:00
* - name-of-trigger
- String
- Name of the trigger
* - schema-name
- String
2019-03-25 20:10:52 +03:00
- Name of the schema for the table
2018-09-11 14:11:24 +03:00
* - table-name
- String
- Name of the table
**In case of** :
- INSERT
- `` event.data.old `` will be `` null ``
- `` event.data.new `` will contain the insert row
- UPDATE
- `` event.data.old `` will be values before the update
- `` event.data.new `` will contain the values after the update
- DELETE
- `` event.data.old `` will contain the row that is deleted
- `` event.data.new `` will be `` null ``
2019-05-13 12:41:07 +03:00
- MANUAL
- `` event.data.old `` will be `` null ``
- `` event.data.new `` will contain the current row
2019-09-13 02:22:01 +03:00
.. note ::
In case of `` UPDATE `` , the events are delivered only if new data is distinct from
old data. The `composite type comparison <https://www.postgresql.org/docs/current/functions-comparisons.html#COMPOSITE-TYPE-COMPARISON> `__
is used to compare the old and new rows. If rows contain columns, which cannot be
compared using `` <> `` operator, then internal binary representation of rows by Postgres is compared.
2018-09-11 14:11:24 +03:00
**For example** :
.. code-block :: json
{
"id": "85558393-c75d-4d2f-9c15-e80591b83894",
"created_at": "2018-09-05T07:14:21.601701Z",
"trigger": {
2019-03-25 20:10:52 +03:00
"name": "test_trigger"
2018-09-11 14:11:24 +03:00
},
"table": {
"schema": "public",
"name": "users"
},
"event": {
2019-01-28 09:12:52 +03:00
"session_variables": {
"x-hasura-role": "admin",
"x-hasura-allowed-roles": "['user', 'boo', 'admin']",
"x-hasura-user-id": "1"
},
2018-09-11 14:11:24 +03:00
"op": "INSERT",
"data": {
"old": null,
"new": {
"id":"42",
"name": "john doe"
}
}
}
}
Syntax definitions
------------------
Object
^^^^^^
.. code-block :: none
{
"column1": "value1",
"column2": "value2",
..
}
OpName
^^^^^^
.. parsed-literal ::
2019-05-13 12:41:07 +03:00
"INSERT" | "UPDATE" | "DELETE" | "MANUAL"
2018-09-11 14:11:24 +03:00
Webhook response structure
--------------------------
A `` 2xx `` response status code is deemed to be a successful invocation of the webhook. Any other response status will be
2018-10-31 15:51:48 +03:00
deemed as an unsuccessful invocation which will cause retries as per the retry configuration.
2018-09-11 14:11:24 +03:00
It is also recommended that you return a JSON object in your webhook response.
2018-10-31 15:51:48 +03:00
Retry-After header
^^^^^^^^^^^^^^^^^^
If the webhook response contains a `` Retry-After `` header, then the event will be redelivered once more after the duration (in seconds) found in the header. Note that the header will be respected only if the response status code is `` non-2xx `` .
The `` Retry-After `` header can be used for retrying/rate-limiting/debouncing your webhook triggers.