Guides/Build scheduled reports with automations

Build scheduled reports with automations

Cron trigger, query analytics, email the results.

Updated March 2026

Schedule automations to run on a cron expression and build recurring reports. This guide creates an analytics site, an email template for the report, and a cron-triggered automation that queries page views and emails the results. The pipeline runs automatically -- no manual intervention after setup.

1. Create an analytics site

Create an analytics site to track page views. Link it to a subdomain for automatic server-side tracking, or use the script tag for external sites.

curl -X POST https://sutrena.com/api/analytics/sites \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "My Website", "subdomainId": "SUB_ID"}'

# Save the site ID from the response

2. Create an email template for the report

Create a template that formats the analytics data as a readable email. Use {{placeholder}} syntax for the dynamic values the automation will provide.

curl -X POST https://sutrena.com/api/email-templates \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weekly Traffic Report",
    "subject": "Weekly report: {{page_views}} page views",
    "body": "<h2>Weekly Traffic Report</h2><p><strong>Page views:</strong> {{page_views}}</p><p><strong>Unique visitors:</strong> {{unique_visitors}}</p><p><strong>Period:</strong> Last 7 days</p><p>View full analytics at <a href=\"https://sutrena.com/dashboard\">your dashboard</a>.</p>"
  }'

# Save the template ID

3. Create the scheduled automation

Create an automation with a schedule trigger (cron expression) that queries analytics and emails the results. This example runs every Monday at 9 AM UTC.

curl -X POST https://sutrena.com/api/automations \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weekly traffic report",
    "slug": "weekly-report",
    "trigger": {
      "type": "schedule",
      "cron": "0 9 * * 1"
    },
    "steps": [
      {
        "type": "query_analytics",
        "name": "views",
        "siteId": "SITE_ID",
        "metric": "page_views",
        "period": "7d"
      },
      {
        "type": "query_analytics",
        "name": "visitors",
        "siteId": "SITE_ID",
        "metric": "unique_visitors",
        "period": "7d"
      },
      {
        "type": "send_email",
        "templateId": "TEMPLATE_ID",
        "to": "[email protected]",
        "data": {
          "page_views": "{{steps.views}}",
          "unique_visitors": "{{steps.visitors}}"
        }
      }
    ]
  }'

# Response includes nextRunAt showing when it will first execute

4. Verify with a test run

Run the automation immediately to verify it works without waiting for the cron schedule. Test runs execute real steps but do not increment counters or write logs.

curl -X POST https://sutrena.com/api/automations/AUTOMATION_ID/test \
  -H "Authorization: Bearer $KEY"

# Response:
# {
#   "data": {
#     "status": "success",
#     "stepsExecuted": 3,
#     "durationMs": 450
#   }
# }

5. Check logs after scheduled execution

After the cron fires, check the logs to confirm the report was sent. Each execution is recorded with trigger source, status, and duration.

curl https://sutrena.com/api/automations/AUTOMATION_ID/logs \
  -H "Authorization: Bearer $KEY"

# Response:
# {
#   "data": [
#     {
#       "triggeredBy": "schedule",
#       "status": "success",
#       "stepsExecuted": 3,
#       "durationMs": 480,
#       "createdAt": "2026-03-17T09:00:01Z"
#     }
#   ]
# }

FAQ

What cron expressions are supported?

Standard 5-field cron: minute hour day-of-month month day-of-week. Examples: "0 9 * * 1" (Monday 9 AM), "0 */6 * * *" (every 6 hours), "0 0 1 * *" (first of month midnight). All times are UTC.

What is the minimum schedule interval?

Free: every 60 minutes. Pro: every 5 minutes. Scale: every minute. The API validates the cron expression against your plan limit on creation.

How many runs per month do I get?

Free: 500/month. Pro: 10,000/month. Scale: 100,000/month. Each scheduled execution counts as one run. The counter resets on the first of each month.

Can I combine analytics queries with other steps?

Yes. Chain any steps after query_analytics: send_email, create_entry (add results to a page), update_page, fetch (call external APIs), or condition (branch based on the metric value). Each step can reference results from previous steps via {{steps.name}}.

What happens if the automation fails during a scheduled run?

The log entry records the error. The automation remains enabled and will run again at the next scheduled time. Failed runs count toward your monthly quota. Check logs to diagnose and fix the issue.

What is Sutrena?

Sutrena is the web runtime for AI agents. Forms, Pages, Dashboards, Analytics, Webhooks, Automations, Emails — all through 75 MCP tools and one REST API. Your agent creates web artifacts, humans interact with them, and your agent gets the data back. Use any one feature or all of them together.

Pages

Deploy HTML instantly

Forms

Collect structured data

Dashboards

Visualize with 7 widget types

Analytics

Privacy-first, no cookies

Webhooks

Slack, Discord, Telegram

Get started in two API calls

1. Get a trial key (no auth, no signup)

curl -X POST https://sutrena.com/api/trial

2. Create anything — a page, form, dashboard, or analytics site

# Create a form with a dashboard
curl -X POST https://sutrena.com/api/forms \
  -H "Authorization: Bearer st_trial_xxx" \
  -H "Content-Type: application/json" \
  -d '{"workflowId": "waitlist", "createDashboard": true}'

# Or deploy a page
curl -X POST https://sutrena.com/api/pages \
  -H "Authorization: Bearer st_trial_xxx" \
  -H "Content-Type: application/json" \
  -d '{"slug": "index", "title": "My Site", "html": "<h1>Live</h1>"}'

Ready to build?

Get a trial API key instantly with no signup, or create an account for the full experience.

Build scheduled reports with automations -- cron + analytics + email | Sutrena | Sutrena