## Webhook Examples and Payload Reference

Alpha Insights webhooks send one JSON payload per run. The run is scheduled (daily, weekly, or monthly at ~1am) and always uses the same structure; only the date range and data change. Below is a simplified payload example and practical ways to use it with Zapier, Make, Slack, or your own endpoint.

### Example Payload (structure)

The body is a single JSON object. This example shows the top-level shape and representative fields. Your actual payload will include more metrics and full order/expense rows.

    {
      "date_from": "2024-01-01",
      "date_to": "2024-01-31",
      "sales_data_summary": {
        "total_order_count": 142,
        "total_order_revenue": 28450.00,
        "total_order_revenue_ex_tax": 25863.64,
        "total_order_cost": 11200.00,
        "total_order_profit": 14663.64,
        "average_order_value": 200.35,
        "average_order_margin": 56.67,
        "total_freight_recovery": 1200.00,
        "total_freight_cost": 800.00,
        "total_payment_gateway_costs": 450.00
      },
      "expense_data_summary": {
        "total_amount": 3200.00,
        "total_amount_paid": 3000.00,
        "average_expenses_per_day": 103.23
      },
      "store_profit_summary": {
        "total_store_profit": 11463.64,
        "average_store_margin": 44.28,
        "daily_average_store_profit": 369.79
      },
      "orders": {
        "12345": {
          "order_id": 12345,
          "date_created": 1704067200,
          "total_order_revenue": 199.00,
          "total_order_cost": 85.00,
          "total_order_profit": 114.00,
          "order_status": "wc-completed",
          "payment_gateway": "stripe",
          "billing_email": "customer@example.com"
        }
      },
      "expenses": [
        {
          "title": "Office supplies",
          "date_created": "2024-01-15",
          "date_paid": "2024-01-20",
          "amount_paid": 150.00,
          "expense_type": "General",
          "recurring_expense": 0,
          "is_paid": 1
        }
      ]
    }

`sales_data_summary`, `expense_data_summary`, and `store_profit_summary` are the same totals you see in Alpha Insights reports for that date range. `orders` is an object keyed by order ID; `expenses` is an array of expense records. Field names and nesting match the data warehouse; use the “Webhook Test Data Output” on the webhook settings page to see the exact structure for your store.

### When the Webhook Fires

- Daily – Every day at ~1am. `date_from` and `date_to` are both yesterday.
- Weekly – Only on Mondays at ~1am. `date_from` is Monday of last week, `date_to` is Sunday of last week.
- Monthly – Only on the 1st at ~1am. `date_from` is the first day of last month, `date_to` is the last day of last month.

There are no per-order or per-event webhooks; every run is a batch for the chosen period.

### Example 1: Zapier – Weekly summary to Google Sheets

Goal: Add one row per week with store profit and order totals.

1. In Zapier, create a Zap. Trigger: Webhooks by Zapier → Catch Hook. Copy the webhook URL.
2. In Alpha Insights, set that URL as the Webhook URL and choose Weekly schedule. Save.
3. Each Monday, Zapier receives the JSON. In the Zap, add Google Sheets → Create Spreadsheet Row.
4. Map fields from the payload, e.g. `date_from`, `date_to`, `store_profit_summary.total_store_profit`, `sales_data_summary.total_order_count`, `sales_data_summary.total_order_revenue`, `sales_data_summary.total_order_profit`.

### Example 2: Make (Integromat) – Daily digest to Slack

Goal: Post a short daily summary to a Slack channel.

1. In Make, create a scenario. Add Webhooks → Custom webhook. Copy the URL.
2. In Alpha Insights, set that URL and choose Daily schedule. Save.
3. In Make, add Slack → Create a Message. Build the message from the webhook body, e.g. “Yesterday: {{sales_data_summary.total_order_count}} orders, {{sales_data_summary.total_order_revenue}} revenue, {{store_profit_summary.total_store_profit}} store profit.”

### Example 3: Custom endpoint – Monthly archive

Goal: Send last month’s full order and expense data to your own API for archiving or BI.

1. Set your API URL in Alpha Insights and choose Monthly schedule. Save.
2. On the 1st at ~1am, your endpoint receives the full JSON: `orders` (all orders in the range), `expenses`, and the three summaries.
3. Your server responds with HTTP 200 after storing or processing the payload. Non-200 responses are logged; 200 updates “last successful webhook” in Alpha Insights.

### Example 4: Zapier – Per-order rows (from batch payload)

Goal: Add a row to a sheet (or CRM) for each order in the webhook payload.

The webhook does not fire once per order; it fires once per schedule with an `orders` object. In Zapier, after the webhook trigger:

1. Use a Formatter or Code step to convert `orders` into an array of order objects (e.g. iterate over the object keys and use each order as an item).
2. Use Google Sheets (or another app) with “Create row” in a loop over that array, mapping `order_id`, `total_order_revenue`, `total_order_profit`, `billing_email`, etc.

For a Daily webhook, that gives you one run per day with all of yesterday’s orders; you then loop and create one row per order.

### Best practices

- Use HTTPS for your webhook URL.
- Respond with HTTP 200 as soon as you’ve accepted the payload so the request doesn’t time out; process or queue the data asynchronously if needed.
- Enable Enable Logging in Alpha Insights when debugging; check the log and error log for failed requests or non-200 responses.
- Use the Test Webhook button to confirm the URL and payload format before relying on the schedule.