When you create a new automation on your site, you must select a trigger that causes the automation to run. A trigger is an event that occurs on a site and gets reported to Wix.
An automation only runs when the trigger occurs. For example, if you select the Member logs in trigger, your automation runs when a member logs in. Most triggers are based on similar business logic, like payment information or contact management.
However, you may want to run your automation when an event occurs that isn't defined by existing triggers. Examples include:
With the Custom Trigger API, you can run an automation for any event that occurs by triggering the automation from your code. This gives you greater control and flexibility over when your automations run.
Once you select the code trigger in the automation builder, you can write your code with the following IDEs:
There are 2 parts to the trigger configuration:
When you select the Velo code trigger as your automation trigger, Wix generates a unique trigger ID. When you call runTrigger(), you need to specify the trigger ID. The method then runs the automation associated with the ID. You can run automations from anywhere in your site code, simply by calling runTrigger() with the relevant ID.
In addition to the ID, you can optionally define a payload schema for the trigger to specify when calling runTrigger(). The structure of the payload schema is generated from sample data that you enter when you configure the trigger. For example, if you enter sample data like this:
Your payload schema will have a structure like this:
The method's payload field is optional even if you define a payload schema. If you do specify a payload, you can't specify a payload with fields that aren't defined in the schema but you can omit fields. Any fields you include in the payload must match the key and type defined in the schema.
For example, if your payload structure looks like the one above, you can pass the following payloads to runTrigger():
Some actions may require certain payload fields to be specified. For example, if subsequent actions need to access contact data, be sure to pass the contact ID field.
If your payload schema contains 1 or more UUID fields, you can mark one of those fields as a contact ID. When the payload is passed to runTrigger(), Wix looks up the ID in the contact ID field. If the ID corresponds to an existing contact, Wix retrieves the contact’s data and attaches that data to the payload. The data can then be passed to any subsequent actions.
Note: If the ID corresponds to a new contact, you can save the contact data by executing the Create a Contact action after the trigger.
Here are some common errors you might encounter and their causes:
| Error message | Cause |
|---|---|
| Automation not found | No automation is found for the trigger ID passed to runTrigger(). This may be because the automation was deleted. |
| This automation can only be executed within its designated application | This only applies to preinstalled automations when an app other than the one that created the automation tries to run it. |