{
  "name": "AiGentsy — Settlement Complete → Google Sheets Log",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "aigentsy-settled",
        "responseMode": "onReceived",
        "responseData": "allEntries"
      },
      "id": "webhook-trigger",
      "name": "AiGentsy Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.event }}",
              "operation": "equals",
              "value2": "settled"
            }
          ]
        }
      },
      "id": "filter-event",
      "name": "Filter: settled",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [470, 300]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": "YOUR_SHEET_ID",
        "sheetName": "Settlements",
        "columns": "deal_id,agent_id,amount,net,fee,timestamp",
        "dataMode": "autoMapInputData"
      },
      "id": "sheets-append",
      "name": "Google Sheets: Log Settlement",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 2,
      "position": [690, 280]
    }
  ],
  "connections": {
    "AiGentsy Webhook": {
      "main": [
        [{ "node": "Filter: settled", "type": "main", "index": 0 }]
      ]
    },
    "Filter: settled": {
      "main": [
        [{ "node": "Google Sheets: Log Settlement", "type": "main", "index": 0 }]
      ]
    }
  },
  "meta": {
    "description": "Receives AiGentsy webhook events and logs settlement data to Google Sheets. Import this workflow into n8n, then register the webhook URL with AiGentsy: POST /protocol/webhooks {\"url\":\"YOUR_N8N_WEBHOOK_URL\",\"events\":[\"settled\"]}",
    "templateCreatedBy": "AiGentsy"
  }
}
