Skip to main content

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"
}
}
warning

If a record is updated (eg, through an API import) but no changes to the Data Record have been made, the @uat timestamp will still be updated and the DataRecordUpdated event will be raised.

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"
}
}

DX Graph 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 https://{{baseUrl}}/triggers
Content-Type: application/json
Authorization: Bearer {{apiKey}}
X-Customer-Code: {{customerCode}}

{
"trigger": {
"eventType": "DataRecordUpdated",
"triggerCode": "call-web-service",
"criteria": "`event.data.dataCollectionCode === '{{collectionCode}}'`",
"name": "Webhook caller",
"description": "Example of calling an external Webhook",
"job": {
"jobType": "callWebservice",
"params": {
"url":"https://webhook.site/{{webhookCode}}",
"method":"POST",
"headers":"",
"body":"`event.data.customerCode`",
"searchParams":""
}
}
}
}
tip

The Parameters for any given Job type support the use of JS Expressions so that you can manipulate and transform the payload from the original Event based on the requirements of the external Webhook.

Recipe: Using DX Engine to Update an Algolia Search Index on DX Graph Record Changes