content/guides/06.automate/4.operations.md
Operations are the individual actions in a flow. They enable you to do things like manage data within Directus, transform the flow's data, send information off to outside services, set conditional logic, trigger other flows, and more.
A condition operation lets you choose a success path or failure path by validating data passed into it with Filter Rules.
This operation does not generate data. If the filter rule is configured properly, it will append a null value on its
operationKey, regardless of if the condition was met or not. However, if the filter rule is misconfigured, it will
append an array containing an object you can use to help debug the misconfiguration.
::callout{icon="material-symbols:info-outline"}
All fields referenced in condition rules must exist in the data being validated. If a field is missing from the payload
(rather than being explicitly null), the condition takes the reject path regardless of the operator. To handle
fields that may be absent, use the inverse operator (such as _nnull) and place your logic on the reject path instead.
::
::callout{icon="material-symbols:warning-rounded" color="warning"}
When using an Event Hook configured to be "Filter (Blocking)", if your flow ends
with a condition that executes with a reject path, it will cancel your database transaction.
::
This operation lets you add a custom script using vanilla JavaScript or TypeScript. The script will be executed securely in an isolated sandbox. No interactions take place between the sandbox and the host except for sharing input and output values. This means, for example, no access to the file system and no ability to do network requests.
The operation provides a default function template. The optional data parameter lets you pass in the data chain as
an argument.
The function's return value will be appended under its <operationKey>.
As an example, let's say you have this function in a script operation, named myScript.
// A key from the data chain
{
"previousOperation": {
"value": 5
}
}
Then you add the following logic via Run Script.
// Your function in the myScript operation
module.exports = function (data) {
return {
timesTwo: data.previousOperation.value * 2,
};
};
The returned value will be appended under the myScript operation key.
{
"previousOperation": {
"value": 5
},
"myScript": {
"timesTwo": 10
}
}
::callout{icon="material-symbols:info-outline"}
Make sure your return value is valid JSON.
::
::callout{icon="material-symbols:info-outline"} Throwing Errors If you throw an error in a Run Script operation, it will immediately break your flow chain and stop execution of subsequent flows. If you used a "Blocking" Event hook, throwing an error will cancel the original event transaction to the database. ::
::callout{icon="material-symbols:info-outline"} Node Modules To prevent unauthorized access to the underlying server, node modules can't be used in the Run Script operation. If you require a third party library for your custom script, you can create a custom operation extension instead. ::
This operation creates item(s) in a collection.
An array with the ID(s) of all items created will be appended under its <operationKey>.
::callout{icon="material-symbols:info-outline"} To learn about payload requirements when creating an item, see API Reference > Items. ::
This operation reads items from a collection and adds them onto the data chain. You may select Items by their ID or by running a query.
An array containing all items read will be appended under its <operationKey>.
This operation updates item(s) in a collection. You may select item(s) to update by their ID or by running a query.
An array containing all items updated will be appended under its <operationKey>.
::callout{icon="material-symbols:info-outline"}
To learn about payload requirements when updating an item, see our Items API reference.
::
This operation deletes item(s) from a collection.
An array with the ID(s) of all items deleted will be appended under its <operationKey>.
This operation lets you sign and verify a JSON Web Token (JWT) using the
jsonwebtoken package.
jsonwebtoken.Based on the operation selected, a JSON Web Token (JWT) or payload will be appended under its <operationKey>.
This operation outputs information to the server-side console as well as the Logs within the Data Studio. This is a key tool for troubleshooting flow configuration. A log operation's key will have a null value on the data chain.
This operation does not generate data for the data chain as its messages are for debugging and troubleshooting. It will
append a null value on the operationKey.
This operation sends emails off to one or more addresses specified.
::callout{icon="material-symbols:warning-rounded" color="warning" to="/configuration/email"} If you are self-hosting Directus, then you need to make sure that email capabilities are correctly configured. Read more on this. ::
WYSIWYG, Markdown, or Template.WYSIWYG and Markdown types. Use the editor to compose the email content.Template. Select the template to use.Template. Variables injected into the selected template.<sup>[1]</sup> These interfaces are tags.
This operation does not generate data for the data chain. It will append a null value on the operationKey.
::callout{icon="material-symbols:info-outline"}
Batch Emails
You can input an array of emails in the To input option to send off multiple emails.
::
::callout{icon="material-symbols:info-outline"}
If you are testing out this operation from localhost:8080, be sure to check your spam box, because your email provider
may send it there automatically.
::
This operation pushes notifications to Directus Users. If the operation executes successfully, a list containing the IDs of all sent notifications generated is appended under this operation's key.
This operation does not generate data. It will append a null value on its operationKey.
::callout{icon="material-symbols:info-outline"}
Batch Notifications
You can input an array of UUIDs in the To input option to send off multiple notifications.
::
This operation makes a request to another URL.
header:value to pass along with the request.When an operation completes successfully, the response is appended under its <operationKey>.
This operation creates a delay in the Flow for a given amount of milliseconds, then continues to the next operation.
This operation does not generate data. It will append a null value on its operationKey.
This operation throws a custom error to halt flow execution with a specific error code, HTTP status, and message.
This operation does not generate data. It immediately throws an error that halts flow execution.
::callout{icon="material-symbols:warning-rounded" color="warning"} When using an Event Hook configured to be "Filter (Blocking)", if your flow ends with a Throw Error operation, it will cancel your database transaction. ::
This operation lets you custom define your own JSON payload for use in subsequent operations. This enables you to take multiple sources of data and consolidate them into a single payload.
When an operation completes successfully, the value you defined under the JSON configuration operation is appended
onto its operationKey.
This operation starts another flow and (optionally) passes data into it. It should be used in combination with the Another Flow trigger.
payload to pass into $trigger on the flow it triggered.Serial, Parallel, and Batch.
Serial: Runs the selected flow for each item in the payload sequentially, starting the next only after the previous execution completes.Batch: Runs the selected flow for each item in the payload concurrently within a batch, starting the next batch only after the previous one completes.Parallel: Runs the selected flow for each item concurrently and waits for all executions to complete, with no guaranteed order.Iteration Mode is set to Batch it defines the number of items processed per batch.If you've configured a response body in the trigger of the other flow, this will be appended under this
operationKey. If no response body is configured, null is appended under this operationKey.
::callout{icon="material-symbols:info-outline"} Flows for-loops If you pass an array to the other flow, the other flow will run once for each item in the array. ::