Documentation
Feedback
Guides
API Reference

Guides
Master DataGetting started
Setting up triggers in Master Data v2

Learn how to create and configure triggers in Master Data v2 to automate actions after a document update.

This guide will teach you how to create and configure triggers in Master Data v2 to automate actions after a document update.

A Master Data trigger is an action executed immediately after a document is inserted or updated.

Master Data v2 supports the following types of triggers:

  • Send an HTTP request.
  • Send an email.
  • Send email using Message Center template.
  • Save data to another data entity.

This article is about Master Data v2 triggers. If you want to use Master Data v1, check the How to create a trigger in Master Data v1 guide.

Before you begin

You may use Master Data v2 triggers to create and add hooks to VTEX first-party apps. To do that, Create a new JSON schema for the data entity used by the app and then follow the instructions below.

Step by step

Each trigger is described as an item of the array v-triggers of a JSON schema. If you want to create a trigger for a data entity with no associated schema, you may create a new schema with the trigger settings according to what is described below.

To create a new trigger in an existing schema, follow these steps:

  1. Get the schema associated with the data entity you wish to add a trigger to.
  2. Copy the JSON schema from the response and create a new object in the v-triggers array, configuring its properties according to your desired behavior. See the Trigger properties and Example sections for more information.
  3. Send the edited schema as the body to the Save schema by name endpoint.

To edit Master Data v2 triggers, follow the steps described above, editing the properties you wish instead of creating a new array item.

Trigger Properties

PropertyTypeDescription
namestringA descriptive name for your trigger, limited to 100 characters.
activebooleanWhether the trigger is enabled (true) or disabled (false).
conditionstringA rule that validates the document before executing the trigger. See the condition section for more information.
runAtobjectThe scheduled date to execute the action. See the runAt section for more information.
weightintegerPercentage value used for A/B testing. See the Setting up an A/B test with Master Data trigger article for more information.
retryobjectDefines the retry policy, specifying the number of attempts and delay between them. See the retry section for more information.
actionobjectThe action that will be executed. See the action section for more information.

Condition

Setting up condition rules is very similar to using query parameters when making a call to Master Data API v2's Search documents. However, differently from the API, you should not include _where in the condition string. Examples: status=ready-for-handling, createdIn between 2001-01-01 AND 2016-01-01, email=my@email.com.

You can create conditions based on any value of any field, including nested fields up to the second level, as exemplified below.


_10
"condition": "Body.ChildOne.ChildTwo=Foo",

To get further information, check the Search documents endpoint reference.

runAt

In case of scheduling an action in the future, you can use the runAt property. See the examples below:

  • Schedule the execution 10 minutes later.

_10
{
_10
"dateTime": "now",
_10
"increment": {
_10
"addMinutes": 10
_10
}
_10
}

  • Schedule the execution six months after the field value createdIn.

_10
{
_10
"dateTime": "{!createdIn}",
_10
"increment": {
_10
"addMonths": 6
_10
}
_10
}

Retry

By default, VTEX Master Data makes three attempts in an interval of 10 minutes. Use this property to override such behavior. See the example below of five attempts in an interval of 30 minutes.


_10
{
_10
"times": 5,
_10
"delay": {
_10
"addMinutes": 30
_10
}
_10
}

Action

Define the action to be executed, which can be one of the following types:

Call an HTTP request

_13
{
_13
"type": "http",
_13
"uri": "http://mydomain.com/api/test",
_13
"method": "POST",
_13
"headers": {
_13
"content-type": "application/json"
_13
},
_13
"body": {
_13
"id": "{!id}",
_13
"test": "TestValue",
_13
"count": 25
_13
}
_13
}

Send an email

_14
{
_14
"type": "email",
_14
"provider": "default",
_14
"subject": "My email with VTEX Master Data",
_14
"to": [
_14
"{!email}",
_14
"test@email.com"
_14
],
_14
"bcc": [
_14
"myemail@test.com"
_14
],
_14
"replyTo": "noreply@company.com",
_14
"body": "My email with document {!id}."
_14
}

Send an email action using a Message Center template.

_24
{
_24
"type": "t-email",
_24
"template": "template-name",
_24
"provider": "default",
_24
"subject": "My template email with VTEX Master Data",
_24
"to": [
_24
"{!email}",
_24
"test@email.com"
_24
],
_24
"bcc": [
_24
"myemail@test.com"
_24
],
_24
"replyTo": "noreply@company.com",
_24
"body": {
_24
"firstName": "{firstName}",
_24
"email": "{email}",
_24
"id": "{!id}",
_24
"clientName": "{!clientProfileData.firstName} {!clientProfileData.lastName}",
_24
"ownerListName": "{!customData.customApps[0].fields.ownerListName}",
_24
"ownerListEmail": "{!customData.customApps[0].fields.ownerListEmail}",
_24
"items": "{!items}",
_24
"openTextField": "{!openTextField.value}"
_24
}
_24
}

Save a document to another data entity.

_10
{
_10
"type": "save",
_10
"dataEntity": "copy",
_10
"json": {
_10
"id": "{!id}",
_10
"message": "{!message}",
_10
"custom": "created/updated by VTEX Master Data triggers"
_10
}
_10
}

Trigger example


_25
{
_25
"properties": {},
_25
"v-triggers": [
_25
{
_25
"name": "copy-document",
_25
"active": true,
_25
"condition": "status=window-to-cancel",
_25
"action": {
_25
"type": "save",
_25
"dataEntity": "copy",
_25
"json": {
_25
"id": "{!id}",
_25
"message": "{!message}",
_25
"custom": "created/updated by VTEX triggers"
_25
}
_25
},
_25
"retry": {
_25
"times": 5,
_25
"delay": {
_25
"addMinutes": 30
_25
}
_25
}
_25
}
_25
]
_25
}

Contributors
3
Photo of the contributor
Photo of the contributor
Photo of the contributor
+ 3 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
3
Photo of the contributor
Photo of the contributor
Photo of the contributor
+ 3 contributors
On this page