content/guides/06.automate/3.triggers.md
A trigger defines the event that starts a flow. This could be from an internal or external activity, such as changes to data, logins, errors, incoming webhooks, schedules, operations from other flows, or even the click of a button within the Data Studio.
There are 5 types of triggers: event hook, webhook, schedule (CRON), "another flow", and manual.
Event Hooks are triggered by events within the platform. The logic is based on Custom API Hooks.
Any data generated by the event will be nested in the $trigger.
payload to your flow, allowing you to
validate or transform payload or even prevent the event transaction.payload. Choose to return:
payload with value from $last.payload with the entire data chain.payload with value from an <operationKey>.::callout{icon="material-symbols:info-outline"}
Events with Multiple Items
If you create items in a single request, the flow will trigger once for each item. If you create three items,
the flow runs three separate times. On each run, just one item will be in the payload.
::
A filter will halt the event transaction, copy the event payload into the flow, let the whole flow run,
optionally replace the original payload by configuring the response body, then resume the event's transaction to
the database.
::callout{icon="material-symbols:info-outline"}
If you're filtering on the items.created scope, the item itself will not have an ID, as it hasn't been created yet.
::
::callout{icon="material-symbols:info-outline"}
Response Body
If no Response Body is configured, the original payload will not be modified, but you'd still have the ability to
cancel the transaction.
::
::callout{icon="material-symbols:info-outline"}
Cancelling Transactions
To completely cancel a transaction, you'll need to throw an error within a
script operation or end the Flow on a failure path.
::
An action lets the event commit its transaction to the database without waiting for the Flow to finish. These are asynchronous, leading them to be more performant, but without the ability to validate or transform the payload before the transaction is committed to the database. However, a copy of the payload is still added into $trigger to use as needed.
Webhooks are triggered on an incoming HTTP request to: /flows/trigger/:this-webhook-trigger-id which you can copy from the webhook
trigger panel.
GET or POST request from the dropdown.$last.<operationKey>.GET requests should be stored and served from cache or the cache should be
bypassed.::callout{icon="material-symbols:info-outline"}
Response Body
If no data is defined in Response Body, the response is empty.
::
::callout{icon="material-symbols:info-outline"}
Asynchronous
If Asynchronous is enabled, the Flows system will immediately resolve/respond to the request without returning a
Response Body, which frees up the API immediately. If it is disabled, the Flows system will wait for the Flow to
finish and return whatever value is in Response Body. This slows the API, but lets you send data.
::
This trigger type enables creating data at scheduled intervals, via 6-point cron job syntax.
┌────────────── second (0-59)
│ ┌──────────── minute (0-59)
│ │ ┌────────── hour (0-23)
│ │ │ ┌──────── day of month (1-31)
│ │ │ │ ┌────── month (1-12)
│ │ │ │ │ ┌──── day of week (0-7)
│ │ │ │ │ │
│ │ │ │ │ │
* * * * * *
This trigger type executes by the trigger Flow operation, allowing chaining Flows.
<operationKey> of
the trigger Flow operation that tripped the trigger. Choose to return:
$last.<operationKey>.::callout{icon="material-symbols:info-outline"}
Flows for-loops
If you pass an array to this trigger, it will run once for each item in the array.
::
This trigger starts your Flow on a manual click of a button within the Data Studio.
The manual trigger must take in item ID(s) before you can click it. On the collection page, the button will be
grayed out until you select some number of items. From the item page, the current item's ID is passed in
automatically. These item IDs are passed in to $trigger as an array.
After the operation runs, a toast notification will appear in your sidebar indicating whether the Flow ran successfully.
If enabled, a confirmation dialog will be shown in a modal before the Flow is executed. There are further options to set up a confirmation dialog.
Each input field can have its own data type, interface, and display options. Some convenience options are also provided to immediately alter the user input (such as trimming whitespace and slugifying text).
Data provided by users when triggering a manual Flow with a confirmation dialog will be accessible in $trigger.body in
the data chain.