See llms.txt for all machine-readable content.

Back to Templates

Build daily sales and support KPI reports from HTTP APIs with file logs

Quick overview

On a schedule or on demand, this workflow pulls a day's orders, revenue, new tickets and first-response time from two REST APIs, compares them with the day before, writes a Markdown report and logs alerts when thresholds are crossed. A failed source shows as missing, never zero.

How it works

  1. A daily schedule (shipped disabled until you test) or the run-now webhook picks the report date: yesterday by default, or a past report_date (YYYY-MM-DD) sent to the webhook.
  2. Configure KPI report holds every setting: the folders, the two source URLs, the thresholds and the timezone.
  3. Get sales numbers and Get support numbers call the two APIs with timeouts, and failures are caught instead of stopping the run.
  4. A Code node checks each reply, takes the report day and the day before and computes the changes. Missing or invalid data is reported as missing, never as zero.
  5. Threshold checks (defaults: a 20% drop in orders or revenue, 60 new tickets, 60 minutes first response) produce alert lines.
  6. The report is saved as kpi-report-YYYY-MM-DD.md (a rerun replaces it), alerts are appended without repeats, and every run writes a log line.

Setup

  1. Use self-hosted n8n with persistent storage (tested on 2.35.7) and allow the Code-node modules fs and path: NODE_FUNCTION_ALLOW_BUILTIN=fs,path.
  2. Open Configure KPI report and fill the five blank fields: reports_dir, alerts_path, runs_log_path, sales_url and support_url. Create the folders.
  3. If your APIs need keys, create HTTP Header Auth credentials and select them on Get sales numbers and Get support numbers.
  4. Set the same timezone in the config and in the workflow settings (default UTC) and review the thresholds.
  5. Call the run-now webhook with a test date, check the saved report and logs, then enable the schedule. Keep the run-now webhook behind a private network or an authenticated gateway.

Requirements

  • Self-hosted n8n (tested on 2.35.7). Not n8n Cloud: the Code nodes write files.
  • NODE_FUNCTION_ALLOW_BUILTIN=fs,path
  • A writable folder for the reports and logs.
  • Two REST APIs that return daily numbers as JSON with a days list: sales days with date, orders and revenue; support days with date, new_tickets and first_response_minutes.
  • Optional: HTTP Header Auth credentials for those APIs.

Customization

  • Change the thresholds, timezone and schedule time in Configure KPI report and the trigger.
  • Map other sources (a database, a payment API, a helpdesk) into the same days format with a mapping node.
  • Send the alert lines to email or chat by adding a node after the alert step.
  • Assign a person to watch gap alerts and write failures.

Additional info

Tested on a fresh self-hosted n8n 2.35.7 against mock APIs shaped like a typical sales and helpdesk API: 518 checks covering normal days, threshold boundaries, missing and invalid data, timeouts, HTTP errors, HTML replies and repeated runs. It has not run against live services, so map your own APIs to the fields above and test with your own data first.