Events and Triggers
DX Graph Events
Various activities performed within the DX Graph raise events that may be acted upon via Triggers.
Examples of DX Graph Events are: DataRecordCreated
, DataRecordUpdated
, DataRecordRemoved
.
Any event can trigger a job, which can be used in scenarios where the external system is listening specifically for the DX Graph event and is ready to perform an action.
The following are example of the events that are raised when a Data Record is created, updated, or removed from a Data Collection in the DX Graph:
Data Record Created
{
"id": "413a2ac8-047e-493e-b2cd-0b55b9a59413",
"type": "DataRecordCreated",
"source": "",
"time": "2023-06-13T13:42:20.951Z",
"data": {
"customerCode": "demo-customer",
"dataCollectionCode":"demo-collection",
"new": {
"dataRecordIdentifier":"12345",
"personId": "12345",
"firstName": "John",
"lastName": "Doe",
"email": "john@acme.com",
"phone": "123-456-7890"
}
}
}
Data Record Updated
{
"id": "413a2ac8-047e-493e-b2cd-0b55b9a59413",
"type": "DataRecordUpdated",
"source": "",
"time": "2023-06-13T13:42:20.951Z",
"data": {
"customerCode": "demo-customer",
"dataCollectionCode":"demo-collection",
"old": {
"dataRecordIdentifier":"12345",
"personId": "12345",
"firstName": "John",
"lastName": "Doe",
"email": "john@acme.com",
"phone": "123-456-7890"
},
"new": {
"dataRecordIdentifier":"12345",
"personId": "12345",
"firstName": "John",
"lastName": "Doe",
"email": "john@fixed-email.com",
"phone": "123-456-7890"
}
}
Data Record Removed
{
"id": "413a2ac8-047e-493e-b2cd-0b55b9a59413",
"type": "DataRecordRemoved",
"source": "",
"time": "2023-06-13T13:42:20.951Z",
"data": {
"customerCode": "demo-customer",
"dataCollectionCode":"demo-collection",
"old": {
"dataRecordIdentifier":"12345",
"personId": "12345",
"firstName": "John",
"lastName": "Doe",
"email": "john@fixed-email.com",
"phone": "123-456-7890"
}
}
Triggers
Reacting to a specific Event is accomplished by setting up Triggers. When defining a trigger, the following is specified:
- the Event Type
- the Trigger Condition
- the Job that will be executed if the Event Type matches and the Trigger Condition is satisfied
To better understand the definition of a Trigger, here is an example that shows how you would call an external Webhook through a Trigger. Here, a 'Call Webservice' Job is triggered when a new record is created in a DX Graph Data Collection.
POST {{mesh_server_url}}/graphql
Content-Type: application/json
Authorization: Bearer {{authorizationToken}}
query ($input: SetTriggerInput) {
setTriggerInput(input: $input)
}
{
"input": {
"customerCode": "acme",
"meshKey": "master",
"triggerEntry": {
"triggerCode": "call-web-service",
"eventType": "DataRecordUpdated",
"trigger": {
"criteria": "....",
"job": {
"jobType": "callWebservice",
"params": {
"url":"",
"method":"",
"headers":"",
"body":"`event.data.customerCode`",
"searchParams":""
}
}
}
}
}
}
The Call Webservice
Job requires the following parameters to be specified in the Trigger definition.
Input Parameters
Parameter | Required | Description |
---|---|---|
url | Yes | The URL of the webservice endpoint to call. |
method | Yes | The HTTP method to use when calling the webservice endpoint. |
headers | No | The headers to include in the request. |
body | No | The body to include in the request. |
searchParams | No | The query parameters to include in the request. |
💡 Tip: Expressions The parameters support the use of javascript expressions so that you can manipulate and transform the payload from the original Event based on the requirements of the external Webhook.