{
  "name": "Price Monitor Lite - Competitor Price Change Alerts",
  "nodes": [
    {
      "parameters": {
        "content": "### How it works\nThis workflow checks one competitor pricing page every 6 hours. It fetches the page, extracts the first visible price, reads your Price History sheet, and compares the new price with the most recent stored snapshot. A move of 1% or more triggers an alert to an incoming webhook (Slack, Discord or any endpoint that accepts JSON). Every run appends a snapshot, so you build a price history without touching a spreadsheet by hand.\n\n### Setup\n1. Replace the competitor URL in Fetch Competitor Page and in Extract Price. Set the competitor name in Extract Price too.\n2. Create a Google Sheets tab named Price History with these exact headers: competitor, url, price, currency, captured_at. Select the Google Sheets credential in both sheet nodes and set the spreadsheet ID.\n3. Replace REPLACE_WITH_ALERT_WEBHOOK_URL with an incoming webhook URL. The request sends both a text field (Slack) and a content field (Discord), so either service accepts it.\n4. Run once to record the baseline. Change the page price by at least 1%, run again and check the alert.\n\n### Customization\nChange the cron expression in Every 6 Hours, adjust the 1% threshold in Compare with History, or extend the extractor for multi-plan pricing. Some sites block bots; use a rendering service if the page returns no price. Tested with n8n 2.48.8 and core nodes only.",
        "height": 440,
        "width": 620,
        "color": 1
      },
      "id": "f1100000-0000-4000-8000-000000000001",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -620,
        -240
      ]
    },
    {
      "parameters": {
        "content": "Fetches one pricing page every 6 hours and extracts the first visible price.",
        "height": 100,
        "width": 520,
        "color": 7
      },
      "id": "f1100000-0000-4000-8000-000000000002",
      "name": "## Capture the price",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -200
      ]
    },
    {
      "parameters": {
        "content": "Reads the Price History sheet and calculates the change against the latest snapshot.",
        "height": 100,
        "width": 520,
        "color": 7
      },
      "id": "f1100000-0000-4000-8000-000000000003",
      "name": "## Compare with history",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        520,
        -200
      ]
    },
    {
      "parameters": {
        "content": "Appends a snapshot, then sends a webhook alert when the price moved 1% or more.",
        "height": 100,
        "width": 560,
        "color": 7
      },
      "id": "f1100000-0000-4000-8000-000000000004",
      "name": "## Alert on change",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1040,
        -200
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 */6 * * *"
            }
          ]
        }
      },
      "id": "f1100000-0000-4000-8000-000000000010",
      "name": "Every 6 Hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "url": "https://REPLACE_WITH_COMPETITOR_URL",
        "options": {
          "timeout": 30000,
          "redirect": {
            "redirect": {
              "followRedirects": true,
              "maxRedirects": 5
            }
          }
        }
      },
      "id": "f1100000-0000-4000-8000-000000000011",
      "name": "Fetch Competitor Page",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const html = typeof $json.data === 'string' ? $json.data : ($json.body || '');\nconst text = String(html).replace(/<script[\\s\\S]*?<\\/script>/gi, ' ').replace(/<style[\\s\\S]*?<\\/style>/gi, ' ').replace(/<[^>]+>/g, ' ');\nconst matches = [...text.matchAll(/([$€£¥]\\s?[0-9][0-9,]*(?:\\.[0-9]{1,2})?)/g)].map((m) => m[1].replace(/\\s/g, ''));\nconst unique = [...new Set(matches)];\nif (!unique.length) throw new Error('No price found on the page. Update the regex for this page layout.');\nconst first = unique[0];\nconst price = Number(first.replace(/[^0-9.]/g, ''));\nif (!Number.isFinite(price)) throw new Error('Could not parse a numeric price from: ' + first);\nreturn [{ json: {\n  competitor: 'REPLACE_WITH_COMPETITOR_NAME',\n  url: 'https://REPLACE_WITH_COMPETITOR_URL',\n  price,\n  currency: first.replace(/[0-9.,\\s]/g, '') || '$',\n  captured_at: new Date().toISOString(),\n  all_matches: unique.slice(0, 10).join(', '),\n} }];"
      },
      "id": "f1100000-0000-4000-8000-000000000012",
      "name": "Extract Price",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        0
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Price History",
          "mode": "name"
        },
        "operation": "read",
        "options": {}
      },
      "id": "f1100000-0000-4000-8000-000000000013",
      "name": "Read Price History",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        780,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const current = $('Extract Price').item.json;\nconst history = [];\nfor (const item of $input.all()) {\n  const r = item.json;\n  const raw = r.price;\n  if (raw === '' || raw === null || raw === undefined) continue;\n  const p = Number(raw);\n  if (!Number.isFinite(p) || p <= 0) continue;\n  history.push({ price: p, captured_at: r.captured_at || '' });\n}\nhistory.sort((a, b) => new Date(b.captured_at) - new Date(a.captured_at));\nconst previous = history.length ? history[0].price : null;\nconst pct = previous !== null ? ((current.price - previous) / previous) * 100 : null;\nconst changed = pct !== null && Math.abs(pct) >= 1;\nconst label = current.currency || '$';\nconst direction = pct !== null && pct >= 0 ? 'up' : 'down';\nconst alert_text = pct === null\n  ? 'Baseline recorded for ' + current.competitor + ': ' + label + current.price + '.'\n  : 'Competitor price change: ' + current.competitor + ' moved ' + pct.toFixed(2) + '% ' + direction + ' from ' + label + previous + ' to ' + label + current.price + '. ' + current.url;\nreturn [{ json: {\n  ...current,\n  previous_price: previous,\n  change_pct: pct === null ? null : Number(pct.toFixed(2)),\n  changed,\n  alert_text,\n} }];"
      },
      "id": "f1100000-0000-4000-8000-000000000014",
      "name": "Compare with History",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1040,
        0
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Price History",
          "mode": "name"
        },
        "operation": "append",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "competitor": "={{ $json.competitor }}",
            "url": "={{ $json.url }}",
            "price": "={{ $json.price }}",
            "currency": "={{ $json.currency }}",
            "captured_at": "={{ $json.captured_at }}"
          },
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "f1100000-0000-4000-8000-000000000015",
      "name": "Append Price Snapshot",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1300,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.changed }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "f1100000-0000-4000-8000-000000000016",
      "name": "Price Changed by 1%?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1560,
        0
      ]
    },
    {
      "parameters": {
        "url": "REPLACE_WITH_ALERT_WEBHOOK_URL",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.alert_text, content: $json.alert_text }) }}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "f1100000-0000-4000-8000-000000000017",
      "name": "Send Alert to Webhook",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1820,
        -100
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Every 6 Hours": {
      "main": [
        [
          {
            "node": "Fetch Competitor Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Competitor Page": {
      "main": [
        [
          {
            "node": "Extract Price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Price": {
      "main": [
        [
          {
            "node": "Read Price History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Price History": {
      "main": [
        [
          {
            "node": "Compare with History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare with History": {
      "main": [
        [
          {
            "node": "Append Price Snapshot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Price Snapshot": {
      "main": [
        [
          {
            "node": "Price Changed by 1%?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Price Changed by 1%?": {
      "main": [
        [
          {
            "node": "Send Alert to Webhook",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "freebie-price-monitor-lite",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
