Directus has the ability to run automated workflows using Flows. These rely on a trigger to start. This article will cover what types of triggers Directus offers and how they trigger a workflow.
To trigger a Flow, you will need to complete the action configured in the workflow, whether that's creating, editing or deleting a record, or waiting for the scheduled time to pass.
Flows is a powerful communication tool that connects your workflows in an easy to use User Interface (UI).
To begin, click on the cog icon to open the settings, then click Flows. Create a new flow to open the trigger options window.
Name the flow accordingly and move onto the Trigger Setup. Here you are presented with all the different types of triggers.
This contains all the internal events that occur in Directus. Use this trigger if you want to run a workflow when a user performs an action. By default, this is an Action which will be processed separately from the internal workflows of Directus. If you want to process this workflow before anything else can run, use Filter to block everything (not recommended) until the workflow is finished.
To trigger an event hook, you must open one of the collections that were included in the scope. Then perform one of the selected action. For example, create a new record, edit an existing record or delete a record.
This creates a URL endpoint in Directus that can be opened by an external application to trigger a workflow. There is the option to POST information or use the default GET to use external information inside the workflow. The link becomes available once the trigger is created.
To trigger a webhook, simply open the URL that was generated by Directus. If you chose to use the POST method, then you'll need an application like Postman to perform the POST action to the URL. The webhook is intended to be used by third party applications to interact with Directus.
You can create a trigger at set intervals exactly like CRON and uses the same syntax (* * * 1 *). For those who are unfamiliar with this or need a refresher. It's in the following order: minutes, hours, day (of the month), month, day (of the week). This website is helpful: https://crontab.guru
To trigger a scheduled workflow, simply set the cron time to a few minutes time then wait for it to run, otherwise, wait for the scheduled time to pass.
This allows you to chain Flows together. There is no option to select the other flow, this must be done when creating the other flow. With this option you can have a collection of common flows which are triggered by various workflows.
This is a tricky one to trigger becuase it relies on another flow being triggered first. If you are unsure how it is triggered, open the other workflow, and note what the first step is. Perform that action and you will see both workflows triggered. If this has not happened, make sure to check the logs on both workflows to find out what stopped the workflow from completing.
This one allows your users to trigger this workflow on-demand for any of the selected collections.
To trigger this flow, open one of the your chosen collections and you'll see a new option in the right-hand side panel labelled Flows. Expand this section to reveal a button labelled with the name of the flow. Click the button and the workflow will run.
Now that you can trigger a workflow in Flows, you can add Actions and Conditions to complete the aims of your workflow.