ExamplesExample

Example: SQL report by e-mail

This is the campaign shape most teams need first: read rows from a database, do something for each one, on a schedule. Every part is a built-in step, so there is no code to maintain — only one query and one e-mail template.

What you will learn
  • Chain a SQL step, a loop and a Send email step
  • Bind each row’s fields into a template

Three steps, no script

The SQL step’s output is { rows, … }. A loop bound to it iterates the rows; inside the loop, item is the current row, so the e-mail step binds item.email as the recipient and item.name and item.total as template values.

The SQL step reads the late orders; the loop sends one e-mail per row, three at a time.

Build it

  1. Add the SQL step

    Press + under Start, choose PostgreSQL, pick the connection and paste the query below.

  2. Add a loop over its rows

    Below it add a Loop, bind its list to the SQL step’s output and set it to parallel with 3 at a time.

  3. Send one e-mail per row

    Inside the loop add Send email: choose a published template that uses {{name}} and {{total}}, bind Recipients to item.email and each template value to the row’s field.

  4. Run it, then schedule it

    Run the flow and check the iterations; then publish it and add a schedule in the Triggers tab, for example every weekday at 08:00.

SQLlate_orders.pg.sql
SELECT c.name, c.email, o.total
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'late'
ORDER BY o.created_at
Expected outputSuccessOne iteration’s Send email output
{
  "ok": true,
  "historyId": "7c1e…",
  "to": [
    "bruno@example.test"
  ],
  "subject": "Your order is late, Bruno Lima"
}

Before it goes live

Send to yourself first: replace the recipient binding with your own address, run, and read the e-mails. A loop iteration that fails does not stop the others when the step is set to continue on error, and an alert rule tells you when a scheduled run fails.