When you create an automation on your site, you must select a trigger that causes the automation to run. A trigger is an event that occurs on your site and gets reported to Wix.
An automation only runs when the event that defines its trigger occurs. For example, if you select the Member logs in trigger, your automation will run 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 is not 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 in 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 Run Trigger, you pass it the trigger ID. The method then runs the automation associated with the ID. The result is that you can run the automation from anywhere in your site code, simply by calling Run Trigger with the relevant ID.
In addition to the ID, you can optionally define a payload schema for the trigger, and pass a payload to Run Trigger. The structure of the payload schema is generated from sample data 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:
Payload fields are optional, so even if you define a payload schema, you’re not required to pass a payload when you call Run Trigger. If you choose to pass a payload, you can omit fields. Any fields you include in the payload should 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 Run Trigger:
Make sure, however, that any fields required by actions are passed. For example, if subsequent actions need to access contact data, be sure to pass the contact ID field.
If your payload schema contains one or more UUID fields, you can mark one of those fields as a contact ID. When the payload is passed to Run Trigger, 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. An app other than the one that created the automation tries to run it. |