Operations
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.
Condition
A condition operation lets you choose a success path or failure path by validating data passed into it with Filter Rules.
Options
- Condition Rules — Create conditions with Filter Rules.
Payload
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.
reject
path, it will cancel your database transaction.Run Script
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.
Options
The operation provides a default function template. The optional data
parameter lets you pass in the data chain as
an argument.
Payload
The function's return
value will be appended under its <operationKey>
.
More Details
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
}
}
return
value is valid JSON.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.
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.
Create Data
This operation creates item(s) in a collection.
Options
- Collection — Select the collection you'd like to create items in.
- Permissions — Select the scope of permissions used for this operation.
- Emit Events — Toggle whether the event is emitted.
- Payload — Defines the payload to create item(s) in a collection.
Payload
An array with the ID(s) of all items created will be appended under its <operationKey>
.
Read Data
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.
Options
- Permissions — Set the scope of permissions used for this operation.
- Collections — Select the collection you'd like to read items from.
- IDs — Input the ID for items you wish to read and press enter. Click the ID to remove.
- Query — Select the items with a query. To learn more, see Filter Rules.
- Emit Events — Toggle whether the event is emitted.
Payload
An array containing all items read will be appended under its <operationKey>
.
Update Data
This operation updates item(s) in a collection. You may select item(s) to update by their ID or by running a query.
Options
- Collection — Select the collection on which you'd like to update items in.
- Permissions — Set the role that this operation will inherit permissions from.
- Emit Events — Toggle whether the event is emitted.
- IDs — Input the ID for Item(s) you wish to update and press enter. Click the ID to remove.
- Payload — Update Items in a collection, using one of the following formats:
- Single object with data, to update items specified in IDs or Query to the same values.
- Single object with keys and data, to update multiple items to the same values.
- Array of objects with data including primary keys, to update multiple items to different values.
- To learn more, see our Items API reference.
- Query — Select items to update with a query. To learn more, see Filter Rules.
Payload
An array containing all items updated will be appended under its <operationKey>
.
payload
requirements when updating an item, see our Items API reference.Delete Data
This operation deletes item(s) from a collection.
Options
- Collection — Select the collection you'd like to delete items from.
- Permissions — Set the scope of permissions used for this operation.
- Emit Events — Toggle whether the event is emitted.
- IDs — Set Item IDs and press enter to confirm. Click the ID to remove.
- Query — Select items to delete with a query. To learn more, see Filter Rules.
Payload
An array with the ID(s) of all items deleted will be appended under its <operationKey>
.
JSON Web Token (JWT)
This operation lets you sign and verify a JSON Web Token (JWT) using the
jsonwebtoken
package.
Options
- Operation — Select the operation you'd like to perform.
- Payload — The string or JSON payload to sign.
- Token — The JSON Web Token to verify or decode.
- Secret — The secret key used to sign or verify a token.
- Options — The options object provided to the operation. For the list of available options, see the
documentation of
jsonwebtoken
.
Payload
Based on the operation selected, a JSON Web Token (JWT) or payload
will be appended under its <operationKey>
.
Log to Console
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.
Options
- Message — Sets a log message.
Payload
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
.
Send Email
This operation sends emails off to one or more addresses specified.
Options
- To — Sets the email addresses. Hit enter to save the email. Click on a pill to remove it.
- Subject — Set the subject line.
- Body — Use a Markdown or WYSIWYG editor to create the email body.
Payload
This operation does not generate data for the data chain. It will append a null
value on the operationKey
.
More Details
You can input an array of emails in the
To
input option to send off multiple emails.localhost:8080
, be sure to check your spam box, because your email provider
may send it there automatically.Send Notification
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.
Options
- Users — Define a user by their UUID. Hit enter to save it. Click on a pill to remove it.
- Permissions — Define the role that this operation will inherit permissions from.
- Title — Set the title of the notification.
- Message — Set the main body of the notification.
Payload
This operation does not generate data. It will append a null
value on its operationKey
.
More Details
You can input an array of UUIDs in the
To
input option to send off multiple notifications.Webhook / Request URL
This operation makes a request to another URL.
Options
- Method — Choose to make a GET, POST, PATCH, DELETE, or other type of request.
- URL — Define the URL to send the request to.
- Headers — Create a new
header:value
to pass along with the request. - Request Body — Set the request body's data.
Payload
When an operation completes successfully, the response
is appended under its <operationKey>
.
Sleep
This operation creates a delay in the Flow for a given amount of milliseconds, then continues to the next operation.
Options
- Milliseconds — Define the number of milliseconds to sleep.
Payload
This operation does not generate data. It will append a null
value on its operationKey
.
Transform Payload
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.
Options
- JSON — Define JSON to insert into the data chain.
Payload
When an operation completes successfully, the value you defined under the JSON configuration operation is appended
onto its operationKey
.
Trigger Flow
This operation starts another flow and (optionally) passes data into it. It should be used in combination with the Another Flow trigger.
Options
- Flow — Define a flow by its primary key UUID.
- Payload — Defines a JSON
payload
to pass into$trigger
on the flow it triggered.
Payload
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
.
More Details
If you pass an array to the other flow, the other flow will run once for each item in the array.