{
  "name": "Zillow Deal-Flow Monitor: ZIP Watcher → $/sqft Scoring → Sheets + Slack (APIllow)",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Watch ZIP codes for new for-sale listings via the APIllow API, score each by $/sqft against the ZIP's median, log everything to Google Sheets (deduped by ZPID, so re-runs never double-count), and alert Slack when a listing prices meaningfully below market. Includes a proper async polling loop, retries, and an error alert channel. Store your APIllow key as a Header Auth credential named x-api-key. Free key at https://apillow.co"
  },
  "nodes": [
    {
      "parameters": {
        "content": "## Zillow Deal-Flow Monitor\nWatches your ZIP codes for new for-sale listings, scores each one by **$ / sqft vs the ZIP median**, logs everything to Google Sheets, and pings Slack when something lists meaningfully below market.\n\n**Setup (~5 min)**\n1. Get a free APIllow key → https://apillow.co\n2. Add a *Header Auth* credential: name `x-api-key`, value = your key\n3. Pick your ZIPs + deal threshold in **Watch config**\n4. Point both Google Sheets nodes at a spreadsheet with a `Deals` tab\n5. Choose your Slack channels (deal alerts + error alerts)",
        "height": 420,
        "width": 520
      },
      "id": "d3a1f001-0001-4001-8001-000000000001",
      "name": "Sticky Note — setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        40,
        -60
      ]
    },
    {
      "parameters": {
        "content": "### Async job pattern\nAPIllow batches are async: the submit call returns a `job_id` instantly and results are fetched separately. **Polling is free — it never counts against your monthly quota.** The loop below re-checks every 10 seconds until the job reports `complete`.",
        "height": 260,
        "width": 560,
        "color": 4
      },
      "id": "d3a1f001-0002-4001-8001-000000000002",
      "name": "Sticky Note — polling",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        880,
        40
      ]
    },
    {
      "parameters": {
        "content": "### Dedup + scoring\nZPIDs already present in your sheet are skipped, so re-runs never create duplicate rows. Every new listing gets a `$ / sqft` figure and is compared to the **median $ / sqft of its ZIP** (computed from the same batch). Anything at or below `deal_threshold × median` is routed to Slack.",
        "height": 280,
        "width": 660,
        "color": 5
      },
      "id": "d3a1f001-0003-4001-8001-000000000003",
      "name": "Sticky Note — scoring",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1560,
        40
      ]
    },
    {
      "parameters": {
        "content": "### If something fails\nBoth API calls retry 3× with a 5s backoff, and any final failure is routed to the ⚠️ Slack alert below instead of dying silently.",
        "height": 200,
        "width": 440,
        "color": 3
      },
      "id": "d3a1f001-0004-4001-8001-000000000004",
      "name": "Sticky Note — errors",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        500,
        760
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "id": "d3a1f001-0005-4001-8001-000000000005",
      "name": "Every day at 8am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        460
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cfg-zips",
              "name": "zipcodes",
              "value": "={{ [44124, 44122] }}",
              "type": "array"
            },
            {
              "id": "cfg-threshold",
              "name": "deal_threshold",
              "value": 0.85,
              "type": "number"
            },
            {
              "id": "cfg-max",
              "name": "max_items",
              "value": 100,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "d3a1f001-0006-4001-8001-000000000006",
      "name": "Watch config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        460
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apillow.co/v1/properties",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"zipcodes\": $json.zipcodes, \"type\": \"sale\", \"max_items\": $json.max_items } }}",
        "options": {}
      },
      "id": "d3a1f001-0007-4001-8001-000000000007",
      "name": "APIllow: submit ZIP search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        460
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "onError": "continueErrorOutput",
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL_ID",
          "name": "APIllow"
        }
      }
    },
    {
      "parameters": {
        "amount": 10,
        "unit": "seconds"
      },
      "id": "d3a1f001-0008-4001-8001-000000000008",
      "name": "Wait for job",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        900,
        460
      ]
    },
    {
      "parameters": {
        "url": "=https://api.apillow.co/v1/results/{{ $('APIllow: submit ZIP search').first().json.job_id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "d3a1f001-0009-4001-8001-000000000009",
      "name": "APIllow: get results",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        460
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "onError": "continueErrorOutput",
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL_ID",
          "name": "APIllow"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "cond-complete",
              "leftValue": "={{ $json.status }}",
              "rightValue": "complete",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d3a1f001-0010-4001-8001-000000000010",
      "name": "Job complete?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1340,
        460
      ]
    },
    {
      "parameters": {
        "amount": 10,
        "unit": "seconds"
      },
      "id": "d3a1f001-0011-4001-8001-000000000011",
      "name": "Wait then re-check",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1340,
        640
      ]
    },
    {
      "parameters": {
        "jsCode": "// Turn the raw job payload into one scored item per listing.\nconst cfg = $('Watch config').first().json;\nconst results = $input.first().json.results || [];\nconst props = results.map(r => r.property).filter(p => p && p.zpid);\n\nconst scored = props.map(p => {\n  const price = Number(p.price) || null;\n  const sqft = Number(p.living_area) || null;\n  const ppsf = price && sqft ? Math.round(price / sqft) : null;\n  const address = [p.street_address, p.city, p.state].filter(Boolean).join(', ');\n  return { ...p, address, price_per_sqft: ppsf };\n});\n\n// Median $/sqft per ZIP, computed from this batch\nconst byZip = {};\nfor (const p of scored) {\n  if (p.price_per_sqft == null || !p.zipcode) continue;\n  (byZip[p.zipcode] ??= []).push(p.price_per_sqft);\n}\nconst median = (arr) => {\n  const s = [...arr].sort((a, b) => a - b);\n  const m = Math.floor(s.length / 2);\n  return s.length % 2 ? s[m] : Math.round((s[m - 1] + s[m]) / 2);\n};\nconst medians = Object.fromEntries(\n  Object.entries(byZip).map(([z, v]) => [z, median(v)])\n);\n\nreturn scored.map(p => {\n  const med = medians[p.zipcode] ?? null;\n  const cutoff = med ? Math.round(med * cfg.deal_threshold) : null;\n  const discount = med && p.price_per_sqft\n    ? Math.round((1 - p.price_per_sqft / med) * 100)\n    : null;\n  return { json: { ...p, zip_median_ppsf: med, deal_cutoff: cutoff, discount_pct: discount } };\n});"
      },
      "id": "d3a1f001-0012-4001-8001-000000000012",
      "name": "Flatten & score",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1580,
        460
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Deals"
        },
        "options": {}
      },
      "id": "d3a1f001-0013-4001-8001-000000000013",
      "name": "Read tracked deals",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1800,
        460
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "// Input = rows already in the sheet; scored listings come from the upstream node.\nconst tracked = new Set(\n  $input.all()\n    .map(i => String(i.json.zpid ?? ''))\n    .filter(s => s && s !== 'undefined')\n);\nconst fresh = $('Flatten & score').all()\n  .map(i => i.json)\n  .filter(p => !tracked.has(String(p.zpid)));\nreturn fresh.map(p => ({ json: p }));"
      },
      "id": "d3a1f001-0014-4001-8001-000000000014",
      "name": "Drop already-tracked",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2020,
        460
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Deals"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "zpid": "={{ $json.zpid }}",
            "date_added": "={{ $now.format('yyyy-MM-dd') }}",
            "address": "={{ $json.address }}",
            "zip": "={{ $json.zipcode }}",
            "price": "={{ $json.price }}",
            "sqft": "={{ $json.living_area }}",
            "price_per_sqft": "={{ $json.price_per_sqft }}",
            "zip_median_ppsf": "={{ $json.zip_median_ppsf }}",
            "discount_pct": "={{ $json.discount_pct }}",
            "beds": "={{ $json.bedrooms }}",
            "baths": "={{ $json.bathrooms }}",
            "status": "={{ $json.home_status }}",
            "zestimate": "={{ $json.zestimate }}",
            "last_sold_price": "={{ $json.last_sold_price }}",
            "last_sold_date": "={{ $json.last_sold_date }}",
            "url": "={{ $json.url }}"
          }
        },
        "options": {}
      },
      "id": "d3a1f001-0015-4001-8001-000000000015",
      "name": "Append to deal sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        2240,
        460
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "cond-has-ppsf",
              "leftValue": "={{ $json.price_per_sqft }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            },
            {
              "id": "cond-below-cutoff",
              "leftValue": "={{ $json.price_per_sqft }}",
              "rightValue": "={{ $json.deal_cutoff }}",
              "operator": {
                "type": "number",
                "operation": "lte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d3a1f001-0016-4001-8001-000000000016",
      "name": "Priced below market?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2460,
        460
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SLACK_CHANNEL"
        },
        "text": "=:rotating_light: *Deal flag — {{ $json.zipcode }}*\n{{ $json.address }}\n${{ $json.price }} · {{ $json.price_per_sqft }}/sqft vs ZIP median {{ $json.zip_median_ppsf }}/sqft ({{ $json.discount_pct }}% below)\n{{ $json.url }}",
        "otherOptions": {}
      },
      "id": "d3a1f001-0017-4001-8001-000000000017",
      "name": "Slack: deal alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        2700,
        460
      ],
      "credentials": {}
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SLACK_CHANNEL"
        },
        "text": "=:warning: Deal-flow monitor: APIllow call failed — {{ ($json.error && ($json.error.message || $json.error.description)) || 'see the n8n execution log' }}",
        "otherOptions": {}
      },
      "id": "d3a1f001-0018-4001-8001-000000000018",
      "name": "Slack: error alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1080,
        820
      ],
      "credentials": {}
    }
  ],
  "connections": {
    "Every day at 8am": {
      "main": [
        [
          {
            "node": "Watch config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Watch config": {
      "main": [
        [
          {
            "node": "APIllow: submit ZIP search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "APIllow: submit ZIP search": {
      "main": [
        [
          {
            "node": "Wait for job",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack: error alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for job": {
      "main": [
        [
          {
            "node": "APIllow: get results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "APIllow: get results": {
      "main": [
        [
          {
            "node": "Job complete?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack: error alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Job complete?": {
      "main": [
        [
          {
            "node": "Flatten & score",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait then re-check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait then re-check": {
      "main": [
        [
          {
            "node": "APIllow: get results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flatten & score": {
      "main": [
        [
          {
            "node": "Read tracked deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read tracked deals": {
      "main": [
        [
          {
            "node": "Drop already-tracked",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drop already-tracked": {
      "main": [
        [
          {
            "node": "Append to deal sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append to deal sheet": {
      "main": [
        [
          {
            "node": "Priced below market?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Priced below market?": {
      "main": [
        [
          {
            "node": "Slack: deal alert",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
