Code Examples

Real-world use cases for every ReportForge endpoint. Each example includes curl, JavaScript, and Python snippets ready to copy and paste.

Sales Summary Expense Report Invoice Inventory Status CSV to Report Automated Reports
1

Sales Summary Report

Generate a professional monthly sales summary from CSV data. The sales-summary template highlights totals, top performers, and category breakdowns.

curl -X POST https://reportforge-api.vercel.app/api/csv-to-report \
  -H "Content-Type: application/json" \
  -d '{
    "csv": "item,amount,quantity,category\nWidget Pro,1250.00,50,Hardware\nGadget Plus,890.50,30,Electronics\nService Plan,2400.00,12,Services\nCable Kit,156.75,100,Accessories\nMonitor Stand,445.00,25,Hardware",
    "template": "sales-summary",
    "title": "February 2026 Sales Report"
  }'
const res = await fetch('https://reportforge-api.vercel.app/api/csv-to-report', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    csv: `item,amount,quantity,category
Widget Pro,1250.00,50,Hardware
Gadget Plus,890.50,30,Electronics
Service Plan,2400.00,12,Services
Cable Kit,156.75,100,Accessories
Monitor Stand,445.00,25,Hardware`,
    template: 'sales-summary',
    title: 'February 2026 Sales Report'
  })
});

const { html, meta } = await res.json();
console.log('Template:', meta.template);
console.log('Rows:', meta.rowCount);

// Open report in a new browser tab
const blob = new Blob([html], { type: 'text/html' });
window.open(URL.createObjectURL(blob));
import requests

response = requests.post(
    "https://reportforge-api.vercel.app/api/csv-to-report",
    json={
        "csv": "item,amount,quantity,category\nWidget Pro,1250.00,50,Hardware\nGadget Plus,890.50,30,Electronics\nService Plan,2400.00,12,Services\nCable Kit,156.75,100,Accessories\nMonitor Stand,445.00,25,Hardware",
        "template": "sales-summary",
        "title": "February 2026 Sales Report"
    }
)

data = response.json()
# Save report to file and open in browser
with open("sales-report.html", "w") as f:
    f.write(data["html"])

import webbrowser
webbrowser.open("sales-report.html")
Sample Response
{
  "html": "<!DOCTYPE html><html>...styled sales summary report...</html>",
  "meta": {
    "template": "sales-summary",
    "rowCount": 5,
    "columns": ["item", "amount", "quantity", "category"],
    "generatedAt": "2026-02-28T14:30:00.000Z"
  }
}
2

Expense Report

Create a formatted expense report from employee spending data. The expense-report template groups by category and calculates subtotals automatically.

curl -X POST https://reportforge-api.vercel.app/api/json-to-report \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"date": "2026-02-03", "description": "Client lunch", "category": "Meals", "amount": 85.50},
      {"date": "2026-02-05", "description": "Taxi to airport", "category": "Travel", "amount": 42.00},
      {"date": "2026-02-05", "description": "Flight to NYC", "category": "Travel", "amount": 340.00},
      {"date": "2026-02-06", "description": "Hotel (2 nights)", "category": "Lodging", "amount": 520.00},
      {"date": "2026-02-07", "description": "Conference ticket", "category": "Events", "amount": 199.00},
      {"date": "2026-02-10", "description": "Office supplies", "category": "Supplies", "amount": 67.25}
    ],
    "template": "expense-report",
    "title": "February 2026 Expenses — Jane Smith"
  }'
const expenses = [
  { date: '2026-02-03', description: 'Client lunch', category: 'Meals', amount: 85.50 },
  { date: '2026-02-05', description: 'Taxi to airport', category: 'Travel', amount: 42.00 },
  { date: '2026-02-05', description: 'Flight to NYC', category: 'Travel', amount: 340.00 },
  { date: '2026-02-06', description: 'Hotel (2 nights)', category: 'Lodging', amount: 520.00 },
  { date: '2026-02-07', description: 'Conference ticket', category: 'Events', amount: 199.00 },
  { date: '2026-02-10', description: 'Office supplies', category: 'Supplies', amount: 67.25 }
];

const res = await fetch('https://reportforge-api.vercel.app/api/json-to-report', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    data: expenses,
    template: 'expense-report',
    title: 'February 2026 Expenses — Jane Smith'
  })
});

const { html } = await res.json();
// Embed in an iframe or save as file
document.getElementById('report-frame').srcdoc = html;
import requests

expenses = [
    {"date": "2026-02-03", "description": "Client lunch", "category": "Meals", "amount": 85.50},
    {"date": "2026-02-05", "description": "Taxi to airport", "category": "Travel", "amount": 42.00},
    {"date": "2026-02-05", "description": "Flight to NYC", "category": "Travel", "amount": 340.00},
    {"date": "2026-02-06", "description": "Hotel (2 nights)", "category": "Lodging", "amount": 520.00},
    {"date": "2026-02-07", "description": "Conference ticket", "category": "Events", "amount": 199.00},
    {"date": "2026-02-10", "description": "Office supplies", "category": "Supplies", "amount": 67.25}
]

response = requests.post(
    "https://reportforge-api.vercel.app/api/json-to-report",
    json={
        "data": expenses,
        "template": "expense-report",
        "title": "February 2026 Expenses -- Jane Smith"
    }
)

with open("expenses.html", "w") as f:
    f.write(response.json()["html"])
print("Expense report saved to expenses.html")
Sample Response
{
  "html": "<!DOCTYPE html>...styled expense report with category subtotals...</html>",
  "meta": {
    "template": "expense-report",
    "rowCount": 6,
    "columns": ["date", "description", "category", "amount"],
    "generatedAt": "2026-02-28T14:30:00.000Z"
  }
}
3

Invoice Generation

Generate a professional, print-ready invoice from order line items. The invoice template formats item rows with quantities, unit prices, and a grand total.

curl -X POST https://reportforge-api.vercel.app/api/json-to-report \
  -H "Content-Type: application/json" \
  -H "X-API-Key: rf_your_api_key" \
  -d '{
    "data": [
      {"item": "Web Design Package", "quantity": 1, "unit_price": 2500.00, "total": 2500.00},
      {"item": "Hosting (Annual)", "quantity": 1, "unit_price": 480.00, "total": 480.00},
      {"item": "SSL Certificate", "quantity": 2, "unit_price": 49.99, "total": 99.98},
      {"item": "Support Hours", "quantity": 10, "unit_price": 75.00, "total": 750.00}
    ],
    "template": "invoice",
    "title": "Invoice #INV-2026-0042"
  }'
const lineItems = [
  { item: 'Web Design Package', quantity: 1, unit_price: 2500.00, total: 2500.00 },
  { item: 'Hosting (Annual)', quantity: 1, unit_price: 480.00, total: 480.00 },
  { item: 'SSL Certificate', quantity: 2, unit_price: 49.99, total: 99.98 },
  { item: 'Support Hours', quantity: 10, unit_price: 75.00, total: 750.00 }
];

const res = await fetch('https://reportforge-api.vercel.app/api/json-to-report', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'rf_your_api_key'
  },
  body: JSON.stringify({
    data: lineItems,
    template: 'invoice',
    title: 'Invoice #INV-2026-0042'
  })
});

const { html } = await res.json();
// Print-ready: open and use Ctrl+P / Cmd+P
const w = window.open('');
w.document.write(html);
w.document.close();
import requests

line_items = [
    {"item": "Web Design Package", "quantity": 1, "unit_price": 2500.00, "total": 2500.00},
    {"item": "Hosting (Annual)", "quantity": 1, "unit_price": 480.00, "total": 480.00},
    {"item": "SSL Certificate", "quantity": 2, "unit_price": 49.99, "total": 99.98},
    {"item": "Support Hours", "quantity": 10, "unit_price": 75.00, "total": 750.00}
]

response = requests.post(
    "https://reportforge-api.vercel.app/api/json-to-report",
    headers={"X-API-Key": "rf_your_api_key"},
    json={
        "data": line_items,
        "template": "invoice",
        "title": "Invoice #INV-2026-0042"
    }
)

# Save as PDF-ready HTML file
with open("invoice-0042.html", "w") as f:
    f.write(response.json()["html"])
print("Invoice saved. Open in browser and print to PDF.")
4

Inventory Status Dashboard

Generate a stock-level dashboard from your inventory data. The inventory-status template highlights low-stock items and color-codes status levels.

curl -X POST https://reportforge-api.vercel.app/api/csv-to-report \
  -H "Content-Type: application/json" \
  -d '{
    "csv": "sku,product,in_stock,reorder_point,status\nSKU-001,Widget Pro,250,50,In Stock\nSKU-002,Gadget Plus,12,25,Low Stock\nSKU-003,Mega Pack,0,10,Out of Stock\nSKU-004,Cable Kit,500,100,In Stock\nSKU-005,Monitor Stand,8,20,Low Stock",
    "template": "inventory-status",
    "title": "Warehouse A — Stock Levels"
  }'
const csv = `sku,product,in_stock,reorder_point,status
SKU-001,Widget Pro,250,50,In Stock
SKU-002,Gadget Plus,12,25,Low Stock
SKU-003,Mega Pack,0,10,Out of Stock
SKU-004,Cable Kit,500,100,In Stock
SKU-005,Monitor Stand,8,20,Low Stock`;

const res = await fetch('https://reportforge-api.vercel.app/api/csv-to-report', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    csv,
    template: 'inventory-status',
    title: 'Warehouse A — Stock Levels'
  })
});

const { html, meta } = await res.json();
console.log(`${meta.rowCount} products tracked`);
document.getElementById('inventory-view').srcdoc = html;
import requests

csv_data = """sku,product,in_stock,reorder_point,status
SKU-001,Widget Pro,250,50,In Stock
SKU-002,Gadget Plus,12,25,Low Stock
SKU-003,Mega Pack,0,10,Out of Stock
SKU-004,Cable Kit,500,100,In Stock
SKU-005,Monitor Stand,8,20,Low Stock"""

response = requests.post(
    "https://reportforge-api.vercel.app/api/csv-to-report",
    json={
        "csv": csv_data,
        "template": "inventory-status",
        "title": "Warehouse A -- Stock Levels"
    }
)

with open("inventory.html", "w") as f:
    f.write(response.json()["html"])
print("Inventory dashboard saved to inventory.html")
5

CSV File to Report

Read a CSV file from disk and send it to the API for report generation. This is the most common workflow for turning exported spreadsheet data into polished reports.

import { readFile, writeFile } from 'node:fs/promises';

// Read CSV exported from your spreadsheet app
const csv = await readFile('./data/monthly-sales.csv', 'utf-8');

const res = await fetch('https://reportforge-api.vercel.app/api/csv-to-report', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': process.env.REPORTFORGE_KEY
  },
  body: JSON.stringify({
    csv,
    template: 'sales-summary',
    title: 'Monthly Sales — From CSV Export'
  })
});

if (!res.ok) {
  const err = await res.json();
  throw new Error(`API error: ${err.code} — ${err.error}`);
}

const { html } = await res.json();
await writeFile('./output/sales-report.html', html);
console.log('Report saved to ./output/sales-report.html');
import os, requests
from pathlib import Path

csv_path = Path("./data/monthly-sales.csv")
csv_text = csv_path.read_text()

response = requests.post(
    "https://reportforge-api.vercel.app/api/csv-to-report",
    headers={"X-API-Key": os.environ["REPORTFORGE_KEY"]},
    json={
        "csv": csv_text,
        "template": "sales-summary",
        "title": "Monthly Sales -- From CSV Export"
    }
)
response.raise_for_status()

output = Path("./output/sales-report.html")
output.parent.mkdir(exist_ok=True)
output.write_text(response.json()["html"])
print(f"Report saved to {output}")
# Read CSV file and send to API
CSV_CONTENT=$(cat ./data/monthly-sales.csv | jq -Rs .)

curl -X POST https://reportforge-api.vercel.app/api/csv-to-report \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $REPORTFORGE_KEY" \
  -d "{
    \"csv\": $CSV_CONTENT,
    \"template\": \"sales-summary\",
    \"title\": \"Monthly Sales\"
  }" | jq -r '.html' > ./output/sales-report.html

echo "Report saved to ./output/sales-report.html"
6

Automated Weekly Reports

Set up a cron job that generates a weekly sales report and sends it via email. This example uses Node.js with nodemailer for email delivery.

// weekly-report.mjs — schedule with: crontab -e
// 0 9 * * 1 node /path/to/weekly-report.mjs
import nodemailer from 'nodemailer';

// Step 1: Fetch this week's data from your database
const salesData = await getWeeklySales(); // your DB query

// Step 2: Generate the report
const res = await fetch('https://reportforge-api.vercel.app/api/json-to-report', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': process.env.REPORTFORGE_KEY
  },
  body: JSON.stringify({
    data: salesData,
    template: 'sales-summary',
    title: `Weekly Sales — ${new Date().toLocaleDateString()}`
  })
});

const { html } = await res.json();

// Step 3: Send via email
const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: 587,
  auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
});

await transporter.sendMail({
  from: 'reports@yourcompany.com',
  to: 'team@yourcompany.com',
  subject: `Weekly Sales Report — ${new Date().toLocaleDateString()}`,
  html: html
});
console.log('Weekly report sent.');
# weekly_report.py — schedule with: crontab -e
# 0 9 * * 1 python3 /path/to/weekly_report.py
import os, smtplib, requests
from email.mime.text import MIMEText
from datetime import datetime

# Step 1: Fetch this week's data
sales_data = get_weekly_sales()  # your DB query

# Step 2: Generate the report
response = requests.post(
    "https://reportforge-api.vercel.app/api/json-to-report",
    headers={"X-API-Key": os.environ["REPORTFORGE_KEY"]},
    json={
        "data": sales_data,
        "template": "sales-summary",
        "title": f"Weekly Sales -- {datetime.now().strftime('%B %d, %Y')}"
    }
)
html = response.json()["html"]

# Step 3: Send via email
msg = MIMEText(html, "html")
msg["Subject"] = f"Weekly Sales Report -- {datetime.now().strftime('%B %d')}"
msg["From"] = "reports@yourcompany.com"
msg["To"] = "team@yourcompany.com"

with smtplib.SMTP(os.environ["SMTP_HOST"], 587) as server:
    server.starttls()
    server.login(os.environ["SMTP_USER"], os.environ["SMTP_PASS"])
    server.send_message(msg)
print("Weekly report sent.")
#!/bin/bash
# weekly-report.sh — add to crontab:
# 0 9 * * 1 /path/to/weekly-report.sh

# Generate report
REPORT=$(curl -s -X POST https://reportforge-api.vercel.app/api/csv-to-report \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $REPORTFORGE_KEY" \
  -d "{
    \"csv\": \"$(cat /data/weekly-sales.csv | jq -Rs .)\",
    \"template\": \"sales-summary\",
    \"title\": \"Weekly Sales — $(date +'%B %d, %Y')\"
  }" | jq -r '.html')

# Save locally
echo "$REPORT" > /output/weekly-report.html

# Email via sendmail (or replace with your SMTP tool)
echo "Subject: Weekly Sales Report
Content-Type: text/html

$REPORT" | sendmail team@yourcompany.com

echo "Weekly report generated and emailed."