{
  "name": "ScoutingAPI — Price-drop watcher",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1
            }
          ]
        }
      },
      "id": "price-drop-watcher-trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -380,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "assign-1",
              "name": "platform",
              "value": "booking",
              "type": "string"
            },
            {
              "id": "assign-2",
              "name": "listingId",
              "value": "abramovic2",
              "type": "string"
            },
            {
              "id": "assign-3",
              "name": "checkIn",
              "value": "",
              "type": "string"
            },
            {
              "id": "assign-4",
              "name": "checkOut",
              "value": "",
              "type": "string"
            },
            {
              "id": "assign-5",
              "name": "adults",
              "value": "2",
              "type": "number"
            },
            {
              "id": "assign-6",
              "name": "currency",
              "value": "EUR",
              "type": "string"
            },
            {
              "id": "assign-7",
              "name": "thresholdValue",
              "value": "2000",
              "type": "number"
            },
            {
              "id": "assign-8",
              "name": "thresholdCurrency",
              "value": "EUR",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "price-drop-watcher-set",
      "name": "Set Inputs",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -160,
        0
      ]
    },
    {
      "parameters": {
        "url": "https://api.scoutingapi.com/v1/price",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "platform",
              "value": "={{ $json.platform }}"
            },
            {
              "name": "listingId",
              "value": "={{ $json.listingId }}"
            },
            {
              "name": "checkIn",
              "value": "={{ $json.checkIn }}"
            },
            {
              "name": "checkOut",
              "value": "={{ $json.checkOut }}"
            },
            {
              "name": "adults",
              "value": "={{ $json.adults }}"
            },
            {
              "name": "currency",
              "value": "={{ $json.currency }}"
            }
          ]
        },
        "options": {}
      },
      "id": "price-drop-watcher-http",
      "name": "ScoutingAPI: Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        60,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_SCOUTINGAPI_CREDENTIAL_ID",
          "name": "ScoutingAPI – Header Auth"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Alert when a stay's total price falls to/below a threshold (a NEW drop only).\n// Input item: { data: Price, meta }. Threshold comes from the 'Set Inputs' node.\nconst staticData = $getWorkflowStaticData('global');\nconst item = $input.first();\nconst data = item?.json?.data || {};\nconst meta = item?.json?.meta || {};\nconst total = typeof data.totalPrice === 'number' ? data.totalPrice : null;\nconst currency = data.currency || meta.currency || 'USD';\nconst threshold = Number($('Set Inputs').first().json.thresholdValue);\nconst previous = typeof staticData.lastNotifiedPrice === 'number' ? staticData.lastNotifiedPrice : null;\nconst belowThreshold = total !== null && total <= threshold;\n// Fire only on a NEW drop: first time below, or a further drop since the last alert.\nconst isNewDrop = belowThreshold && (previous === null || total < previous);\nstaticData.lastNotifiedPrice = belowThreshold ? total : null;\nif (!isNewDrop) return [];\nconst message =\n  ':money_with_wings: Price-drop alert\\n' +\n  `Listing ${data.platform}/${data.listingId}\\n` +\n  `Total: ${total} ${currency} (threshold ${threshold} ${currency})\\n` +\n  `Nightly: ${data.nightlyPrice ?? '—'} ${currency} · ${data.nights ?? '—'} nights\\n` +\n  `${data.url ?? ''}\\n` +\n  `Credits charged: ${meta.creditsCharged ?? 0} · requestId ${meta.requestId ?? ''}`;\nreturn [{ json: { total, threshold, currency, belowThreshold, previous, message } }];"
      },
      "id": "price-drop-watcher-code",
      "name": "Check Price Drop",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        0
      ]
    },
    {
      "id": "price-drop-watcher-delivery",
      "position": [
        500,
        0
      ],
      "parameters": {
        "authentication": "accessToken",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "REPLACE_WITH_SLACK_CHANNEL_ID",
          "mode": "id"
        },
        "text": "={{ $json.report }}",
        "otherOptions": {}
      },
      "name": "Send Report",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "credentials": {
        "slackApi": {
          "id": "REPLACE_WITH_SLACK_CREDENTIAL_ID",
          "name": "Slack account"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Inputs": {
      "main": [
        [
          {
            "node": "ScoutingAPI: Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ScoutingAPI: Request": {
      "main": [
        [
          {
            "node": "Check Price Drop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Price Drop": {
      "main": [
        [
          {
            "node": "Send Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "versionId": "scoutingapi-price-drop-watcher-v1",
  "tags": []
}
