Guides/Build scheduled reports with automations

Build scheduled reports with automations

Cron trigger, query analytics, update a page with the results.

Updated March 2026

Schedule automations to run on a cron expression and build recurring reports. This guide creates an analytics site, a report page with an entry template, and a cron-triggered automation that queries page views and adds the results as a page entry. 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 a report page with an entry template

Create a page that displays report entries. The entry template defines how each report snapshot renders. New entries appear at the top, so you get a running history of weekly metrics.

curl -X POST https://sutrena.com/api/pages \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "weekly-report",
    "title": "Weekly Traffic Report",
    "html": "<h1>Weekly Traffic Report</h1><p>Updated automatically every Monday at 9 AM UTC.</p><!-- sutrena:entries -->",
    "entryTemplate": "<div style=\"border-bottom:1px solid #eee;padding:16px 0\"><h3>Week of {{date}}</h3><p><strong>Page views:</strong> {{page_views}}</p><p><strong>Unique visitors:</strong> {{unique_visitors}}</p></div>"
  }'

# Save the page ID

3. Create the scheduled automation

Create an automation with a schedule trigger (cron expression) that queries analytics and adds the results as a page entry. 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": "create_entry",
        "pageId": "PAGE_ID",
        "data": {
          "date": "{{trigger.timestamp}}",
          "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 generated. 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: 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}}.

Can I get the report via webhook instead?

Yes. Replace the create_entry step with a fetch step that POSTs the analytics data to a webhook URL (Slack, Discord, or your own endpoint). You can also add both -- update a page and send a webhook notification in the same automation.

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, Analytics, Webhooks, Automations — all through 67 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

Automations

DSL-based pipelines with 14 step 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, automation, or analytics site

# Create a form
curl -X POST https://sutrena.com/api/forms \
  -H "Authorization: Bearer st_trial_xxx" \
  -H "Content-Type: application/json" \
  -d '{"name": "waitlist", "fields": [{"name": "email", "label": "Email", "type": "email", "required": 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 + page update | Sutrena | Sutrena