Lesson 6: Plug in the website and a daily report
Goal: The website form posts straight in, and a small script sends Arjun a daily pipeline report.
This lesson is for the developer. Skip it if you don’t write code: everything before it works without any.
Part 1: Post the form from the server
Section titled “Part 1: Post the form from the server”In Lesson 1 the form posted straight to the webhook URL, so the visitor saw Auto Appy’s JSON reply. Posting from the website’s server keeps the visitor on Skyline’s own thank-you page.
<?php// enquiry.php: the form posts here; we forward to Auto Appy and redirect.$payload = [ 'name' => trim($_POST['name'] ?? ''), 'phone' => preg_replace('/\D/', '', $_POST['phone'] ?? ''), 'project' => $_POST['project'] ?? '', 'bhk' => $_POST['bhk'] ?? '', 'budget' => preg_replace('/\D/', '', $_POST['budget'] ?? ''), 'message' => trim($_POST['message'] ?? ''),];if (strlen($payload['phone']) === 10) $payload['phone'] = '91' . $payload['phone'];
$ch = curl_init(getenv('AUTOAPPY_WEBSITE_TRIGGER_URL'));curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Accept: application/json'], CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_TIMEOUT => 20,]);curl_exec($ch);curl_close($ch);header('Location: /thank-you');app.post('/enquiry', express.urlencoded({ extended: false }), async (req, res) => { const digits = (v = '') => String(v).replace(/\D/g, ''); let phone = digits(req.body.phone); if (phone.length === 10) phone = '91' + phone; await fetch(process.env.AUTOAPPY_WEBSITE_TRIGGER_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ ...req.body, phone, budget: digits(req.body.budget) }), }).catch(() => {}); // never block the visitor on our automation res.redirect('/thank-you');});Two things this fixes at the source: phone numbers always get the 91 country code, and budgets are plain digits, so Lesson 2’s number conditions work.
Part 2: A daily report with an API key
Section titled “Part 2: A daily report with an API key”-
In Auto Appy, Settings → API keys → Create API key. Key name
Open API keysautoappy.com/settings/api-keysDaily pipeline report, Access Read and write (run history needs it today), Expiration After one year. Generate key and copy it once. -
Store it on the server as
AUTOAPPY_API_KEY. -
Schedule the script below to run at 8 pm (cron, or the hosting panel’s scheduler).
# daily_report.py: summarise today's runs for every Skyline workflowimport os, datetime, collections, requests
API = "https://api.autoappy.com"H = {"Authorization": f"Bearer {os.environ['AUTOAPPY_API_KEY']}", "Accept": "application/json"}today = datetime.datetime.now(datetime.timezone.utc).date().isoformat()
lines = []for wf in requests.get(f"{API}/workflows", headers=H, timeout=30).json()["workflows"]: data = requests.get(f"{API}/workflows/{wf['id']}/executions", params={"status": "all", "per_page": 50}, headers=H, timeout=30).json() runs = [r for r in data.get("data", []) if (r.get("executed_at") or "").startswith(today)] if not runs: continue failed = sum(1 for r in runs if r.get("outcome") == "failed") sources = collections.Counter((r.get("trigger") or {}).get("name", "Main") for r in runs) by_source = ", ".join(f"{name} {n}" for name, n in sources.most_common()) lines.append(f"{wf['name']}: {len(runs)} runs ({by_source}), {failed} failed")
report = "Skyline today\n" + ("\n".join(lines) or "No runs today.")print(report)# Send it however you like: email, or a webhook into an Auto Appy workflow that WhatsApps Arjun.Each run in the history response has executed_at, outcome (succeeded, failed, or still running) and trigger (which source started it). Pages hold up to 50 runs; read meta.last_page and add page=2… for busier workflows. Full details are in the API reference.
- Send the report only when something failed, and otherwise just once a week.
- Revoke the key and run the script. What status code do you get?
- Rewrite the PHP handler so it also stores the enquiry in your own database before forwarding.
- Webhook URLsPost from a server for a clean thank-you page and clean data.
- API keysOne named key per integration, with an expiry; revoke any time.
- REST APIList workflows, read run history, change status, run workflows.
For trainers: how to teach this lesson
- For mixed classes: run Part 1 as a demo for non-developers (“this is why the thank-you page looks nicer”), and let developers do Part 2 hands-on.
- Security moment: ask where each secret lives (webhook URL, API key) and who could misuse it.
