Retool Workflows quickstart
Retool Workflows enables you to build, schedule, and monitor jobs, alerts, and ETL tasks. You can automate processes without the need for user interaction and take action based on conditions.
This guide explains how to automate an ETL task using Retool Workflows and sample subscription data. Once complete, this workflow sends a weekly message with the number of subscriptions due to expire. If there aren't any expiring soon, it sends a different message.
1. Generate a test API with sample data
You can connect to almost any data source and make it available as a resource for your apps. Retool provides built-in integrations for you to automatically connect different types of data sources with minimal configuration.
Retool also includes a RESTQuery resource that enables you to interact with REST APIs on a per-app or per-workflow basis. This allows you to interact with APIs without needing to first create a resource for them.
This guide uses a test API with sample data that was created using Retool's REST API generator app.
Column title | Data type | Description |
---|---|---|
company | People / Company | The company with an active subscription. |
plan | People / Plan | The subscription plan for the company. |
contact | People / Email Address | The company's contact email addresses. |
expires | Date | The expiration date of the subscription. |
Use the embedded app below to create your own test API with sample data to try out Retool Workflows without connecting any data sources of your own. Sample data is automatically populated and you only need to specify a date range for the expire
column. Select a date range from today to a future date (e.g., 30 days).
Click Generate API to instantly generate a test API and receive its URL. Make a note of the Endpoint URL as you will use this in the workflow.
2. Create a new workflow
Sign in to your Retool organization, select the Workflows tab in the navigation bar, then click Create new > Workflow.
Workflows are comprised of blocks that perform specific actions, such as interacting with data or performing custom logic. You connect blocks together to define their control flow, which represents the order of operation in which they run.
The workflow initially contains two blocks:
- Start: Configure settings to trigger the workflow automatically using a schedule or in response to webhook events.
- Resource query: Interact with connected data sources or run custom JavaScript to output data.
A workflow's name is initially set using the name of the current user and the creation date. Click the name of this workflow in the title bar and set it to Subscription Bot
.
3. Get subscriptions data
Select the query1 Query block and rename it to getSubscriptions
by clicking the name in the block's title bar. Change the Resource to RESTQuery, select the GET action type, and provide your test API's URL.
Click ▸ to run the query and view the results. You can click the Table switch to view the API response in a table.
4. Filter expiring subscriptions
Next, the workflow must filter the subscriptions data to exclude any that aren't due to expire in the next 24 hours. You do this with the Filter block and return only subscriptions that meet this condition.
There are two methods for adding and connecting blocks:
- Click and drag ⦿ from an existing block. This automatically creates a connection between blocks.
- Click + in the toolbar to add a block. You must then click-and-drag ⦿ from one block to another.
Whichever method you use, add a Filter block and set its name to getExpiringSubscriptions
. A line appears to show the connection of one block to another.
Retool includes a number of third-party JavaScript libraries. You can use Moment.js to work with date values in any Retool app or workflow. Set the Filter Expression to the following JavaScript statement and return only subscriptions that expire within the next day.
moment(value.expires).isBetween(moment.now(), moment().add(1, "day"));
The Filter block loops through each item and evaluates the expires
date. If this is within the next 24 hours, the condition evaluates as true
and the item is returned by the Filter block.
Finally, set the block's name to getExpiringSubscriptions
.
5. Perform conditional actions
This workflow only needs to send a message if there are subscriptions nearing expiration. If there are no subscriptions expiring soon, it should perform a different action.
Instead of writing an if...else statement in JavaScript, use the Branch block to define conditions. This is useful for breaking out complex JavaScript logic into more manageable blocks of code.
Add a Branch block that's connected from getExpiringSubscriptions. Each part of the statement has its own connecting point and only runs if the evaluated condition is a truthy value.
Set the If statement's condition to getExpiringSubscriptions.data.length > 0
so that it runs only if there are any expiring subscriptions.
6. Format the message for expiring subscriptions
The message sent by this workflow should include the number of subscriptions expiring this week. You can write JavaScript to transform this data and count the subscriptions, then return a formatted message that is ready to send.
Add a Query block that's connected from the If statement in the Branch block, then set its name to formatExpirationsMessage
. Select Run JS Code in the dropdown menu of resources, and include the following JavaScript:
const subs = getExpiringSubscriptions.data;
const message =
workflowContext.name +
": You have " +
subs.length +
" subscription(s) expiring this week!";
return message;
Click ▸ to run the query. This JavaScript code uses workflowContext to include details of the current workflow. You can reference other information about a workflow using this property, such as workflowContext.lastRun
.
This results in the following message:
Retool Workflows Subscriptions Bot: You have 10 subscription(s) expiring this week!
7. Format the message for no expiring subscriptions
If there are no expiring subscriptions, the workflow sends a different message. Click Add Branch to the Branch block to create an Else statement. Next, add a Query block that's connected from the Else statement in the Branch block, then set its name to formatNoExpirationsMessage
.
Select Run JS Code in the dropdown menu of resources, and include the following JavaScript:
const message =
workflowContext.name + ": No subscriptions are set to expire this week.";
return message;
8. Send the message
Both formatExpirationsMessage
and formatNoExpirationsMessage
blocks output a formatted message. You can send the message using resources like SMTP or SendGrid for email, Twilio for SMS, or Slack for team messaging.
This workflow sends either message using Slack. Instead of configuring multiple Query blocks or writing conditional JavaScript, you can create Functions that operate as reusable blocks which can be called within other blocks.
Functions use parameters to pass data when called from a block. Both of the Query blocks that format a message can pass the formatted message to the function.
- Click + in the Functions section of the left panel to add a new function, set its name to
sendMessage
, and select a resource to use (e.g., Slack). - Each parameter must have a test value so it can perform a test run without being called, so set the test value for
param1
toHello, World!
. - Set the Message value to
{{ param1 }}
,
Functions use the await operator and there is no data that the query needs to return. After creating a function, replace return message;
in both formatExpirationsMessage and formatNoExpirationsMessage blocks with await sendMessage(message);
.
9. Configure a schedule
With the workflow set up, configure a weekly schedule that triggers it automatically:
- Click on the Start block.
- Select the Schedule trigger.
- Select the Interval schedule type.
- Set a weekly schedule to run at a specific time (e.g., 4pm PDT).
You can click Go to Start to jump back to the Start of your workflow.
10. Test and enable the workflow
You can manually run the workflow to check it performs as expected by clicking the Run button in the toolbar. Workflows run manually display the current run log at the bottom of the screen that updates in real time.
Workflows do not run automatically until you deploy and enable them. Click Deploy in the toolbar to deploy the latest changes to your workflow, then click Run to test it out. If the workflow performs as expected, toggle the Enable setting in the toolbar so it can run automatically on a schedule.
Wrap up
At this point, you've built a workflow that automatically retrieves a list of subscriptions and notifies you each week of any that are due to expire.
A lot of Retool's value comes in the combination of low and no-code solutions with writing custom queries and JavaScript. Workflows can automate many tasks that involve your data sources without the need for user interaction.