Skip to main content

Tutorials

Learn how to build business software on Retool for different use cases.

Build a workflow that automatically responds to customers using Retool AI

· 8 min read

With Retool AI, you can build AI-powered workflows. AI actions enable you to interact with AI models using your data and perform a range of actions, such as:

AI actions are available to in both apps and workflows. The following guide explains how to create a workflow that is triggered by a webhook whenever a customer submits a returns request. It uses AI to determine if the customer is requesting a refund or replacement, then responds to the customer with relevant information using Retool Email.

Build an app that generates return details for customers using Retool AI

· 4 min read

With Retool AI, you can build AI-powered apps. AI actions enable you to interact with AI models using your data and perform a range of actions, such as:

  • Generate text, images, and chat responses.
  • Analyze, classify, and summarize text.
  • Generate images.

AI actions are available to in both apps and workflows. The following guide explains how to create a web app that automatically completes a return request for a customer's defective product. It uses AI Actions to generate a fake support ticket and extract relevant information to prefill input fields in a form.

Run an API request for each row in a table

· 3 min read

This examples makes an API request for each row in a table, and then shows any errors returned in the process.

1. Add a table

Add a Table component to your app. Select Use an array in the Data source dropdown menu, then paste this JSON into the Data source attribute.

[
{
"id": 1,
"name": "Hanson Deck",
"email": "hanson@deck.com",
"sales": 37
},
{
"id": 2,
"name": "Sue Shei",
"email": "sueshei@example.com",
"sales": 550
},
{
"id": 3,
"name": "Jason Response",
"email": "jason@response.com",
"sales": 55
},
{
"id": 4,
"name": "Cher Actor",
"email": "cher@example.com",
"sales": 424
},
{
"id": 5,
"name": "Erica Widget",
"email": "erica@widget.org",
"sales": 243
}
]

2. Create a query

Create a query using the RestQuery (restapi) resource. Set the Action type to Post and use this URL: https://approvals.tryretool.com/api/users/approve?email={{table1.data[i].email}}. The URL parameters are populated automatically.

By default, the i property is 0 but JavaScript in a subsequent step will increment this value so the query runs on each row.

Adding a REST query

3. Add a Button and Text components

Add a Button and two Text components to your app. Status shows the query's progress and Errors displays any errors while the query runs.

4. Write the JavaScript query

Create a JavaScript query named query2 and add the following JavaScript.

var rows = table1.data;
var errors = "";
var total = rows.length;

function runQuery(i) {
// Update the Status text
Status.setValue("Progress: " + (i.toString() + "/" + total.toString()));

if (i >= rows.length) {
console.log("Finished running all queries");
return;
}

console.log("Running query for row", i);

query1.trigger({
additionalScope: { i: i }, // This is where we override the `i` variable
// You can use the argument to get the data with the onSuccess function
onSuccess: function (data) {
runQuery(i + 1);
},
onFailure: function (error) {
// Update the Errors text
errors += "Found error at line " + i.toString() + ": " + error + "\n\n";
Errors.setValue(errors);
runQuery(i + 1);
},
});
}

runQuery(0);

5. Add an event handler to your button

After saving query2, add an event handler to your button that triggers the JavaScript query.

Now click the Submit button to test the app. As the query runs on each row, the status updates and errors are displayed. Since the API endpoint at https://approvals.tryretool.com/api/users/approve doesn't exist, all the requests fail.

Connect to Google Cloud SQL

· 5 min read

You can connect to Google Cloud SQL and make your managed PostgreSQL or MySQL databases available as resources in Retool. Once complete, your users can write queries that interact with your data.

Requirements

All users for Retool organizations on Free or Team plans have global Edit permissions and can add, edit, and remove resources. If your organization manages user permissions for resources, you must be a member of a group with Edit all permissions.

To create a PostgreSQL resource, you need:

  • Cloud SQL authentication credentials for the PostgreSQL database.
  • Connection details for the PostgreSQL database host. This includes the hostname, port, and database name.
  • Firewall rules that allow Retool to access Cloud SQL.

Retool authenticates with Cloud SQL for PostgreSQL databases using a username and password. You should create an additional user for this purpose and not reuse existing credentials. This provides more granular control and allows you to manage the scope of permissions.

You must allow access from Retool's IP addresses. Add the IP addresses to your firewall's Allowlist before you create the resource. Refer to the Cloud SQL documentation for guidance on authorizing access to Cloud SQL.

1. Create the resource

Sign in to your Retool organization and create a new PostgreSQL resource from the Resources tab.

2. Configure the resource

Specify a name and location for the PostgreSQL resource. Retool displays the resource name and type in query editors to help users identify them.

Next, configure the General and Authentication settings.

General settingDescription
HostThe publicly available IP address.
PortThe port number. Default is 5432.
Database nameThe name of the database.
Connection optionsAdditional connection options to use with Retool.

Select User and Password as the authentication method, then provide the following information.

Authentication settingDescription
Database usernameThe username.
Database passwordThe password.

Specify whether to connect using SSL. PostgreSQL resources are initially configured to use SSL by default. If required, you can provide CA certificate, client key, and client certificate credentials.

Configure user and password authentication

3. Test and save

Click Test Connection to verify that Retool can connect to Cloud SQL. If the test fails, check the resource settings and try again. Testing a connection only checks whether Retool can successfully connect to the resource. It cannot check whether the provided credentials have sufficient privileges or can perform every supported action.

Click Create resource to complete the setup. You can then click either Create app to immediately start building a Retool app or Back to resources to return to the list of resources.

Wrap up

Your Cloud SQL resource is now ready to use. To interact with Cloud SQL data, select the resource in the query editor. You can read data using SQL queries, write data using GUI queries (if enabled), and use the schema browser to search tables or columns.