Before diving in, it's important to understand the difference between a trigger and an event and what all this means for your users.
A trigger is the configuration you create for your app in your app's dashboard. On the other hand, an event is what takes place in your service, which you then report to Wix.
The distinction between triggers and events is hidden from your users. From their perspective,they interact with triggers only. Users who install your app are able to use your triggers when they create new automations for their site. When your app reports an event, all site automations that use the specified trigger are activated.
Wix Automations supports 2 types of events for triggers: real-time events and scheduled events.
Each trigger can support either real-time events or scheduled events, but not both. However, you can call reportEvent() multiple times in response to a single business event in your system.
This table lays out the differences between real-time events and scheduled events:
Real-time event | Scheduled event |
---|---|
Takes place the moment it's reported. | Takes place at a date and time specified in the payload. |
Supported by default in new triggers. | Supported only when your trigger meets both of these criteria:
|
Supports automation actions:
| Supports automation actions:
|
Your users may configure actions to be carried out some time after you report an event. If you create a trigger for something that could be canceled or deleted, we strongly recommend canceling events when they're no longer relevant. If your app doesn't cancel events, your users' automations may carry out undesired actions, like sending overdue notices for invoices after they've been paid.
Events are not cancelable by default. To make an event cancelable, you must first pass an externalEntityId
and the applicable triggerKey
to reportEvent(). When you call cancelEvent() with the same externalEntityId
and triggerKey
, the event is canceled, as are all other events that share the same externalEntityId
and triggerKey
.
externalEntityId
It's important to know that the Cancel Event endpoint cancels all events with the specified combination of triggerKey
and externalEntityId
. You must think through your implementation carefully to make sure you don't pass an externalEntityId
that could cancel events you don't mean to cancel.
Consider what kind of relationship between entities you're trying to support. These general guidelines might help you decide what ID to use for externalEntityId
:
If you're supporting a one-to-many relationship, use the ID from the many side of the relationship.
For example, in a contact-to-invoices relationship: An invoice relates to a single contact, but a contact can relate to multiple invoices. The invoice ID is the appropriate externalEntityId
.
If you're supporting a many-to-many relationship, create a unique event ID for each reported event.
For example, in a students-to-classes relationship: Each student relates to multiple classes, and each class relates to multiple students. A new event ID is the appropriate externalEntityId
.
Important: The scenarios here are for illustration only. Always evaluate your implementation against your users' real-world requirements.
The scenario: Customers can schedule appointments with site collaborators.
Suggested value for externalEntityId
: Appointment ID
Suggested triggers and how your users might use them:
Trigger key and description | How your users might use the trigger |
---|---|
Real-time event. Triggered when someone schedules an appointment. |
|
Scheduled event. Triggered in relation to the appointment's start time. |
|
Real-time event. Triggered when someone cancels an appointment. |
|
Example logic for your app:
Business event | Your app's API calls |
---|---|
Customer schedules an appointment |
|
Customer cancels an appointment |
|
The scenario: Participants can enroll in multiple courses. Each course can contain multiple participants.
Suggested value for externalEntityId
: A generated enrollment ID, unique to each student-class combination.
Suggested triggers and how your users might use them:
Trigger key and description | How your users might use the trigger |
---|---|
Real-time event. Triggered when someone signs up for a class. |
|
Scheduled event. Triggered in relation to the class's start time. |
|
Real-time event. Triggered when someone is unenrolled from a class. |
|
Real-time event. Triggered when a class is canceled. |
|
Example logic for your app:
Business event | Your app's API calls |
---|---|
Participant enrolls in a class |
|
Participant leaves a class |
|
Class is canceled |
|