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
  • Read each row’s fields into a template

Three steps, no script

The SQL step’s output is { rows, … }. A loop reading it iterates the rows; inside a loop named each_order, nodes.each_order.item is the current row, so the e-mail step reads nodes.each_order.item.email as the recipient and nodes.each_order.item.name and nodes.each_order.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 Flow inputs, choose PostgreSQL, label it Late orders, pick the connection and paste the query below.

  2. Add a loop over its rows

    Below it add a Loop labelled Each order, set its Items to nodes.late_orders.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}}, set Recipients to nodes.each_order.item.email and each template value to the row’s field, such as nodes.each_order.item.name.

  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 with your own address in quotes, 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.