{
  "name": "Phuket Radar - Scheduled Scrape",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 2
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Every 2 Hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.PHUKETRADAR_BASE_URL || 'https://phuketradar.com' }}/api/cron/scrape",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": false,
        "options": {
          "timeout": 300000
        }
      },
      "id": "trigger-scrape",
      "name": "Trigger Scrape",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.statusCode || $response.statusCode }}",
              "rightValue": 200,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ]
        }
      },
      "id": "check-success",
      "name": "Check Success",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\n\nconst summary = {\n  status: 'SUCCESS',\n  timestamp: new Date().toISOString(),\n  result: response\n};\n\nconsole.log('\u2705 Scrape completed successfully:', JSON.stringify(summary, null, 2));\n\nreturn [{ json: summary }];"
      },
      "id": "log-success",
      "name": "Log Success",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        920,
        200
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\nconst error = {\n  status: 'FAILED',\n  timestamp: new Date().toISOString(),\n  statusCode: response.statusCode,\n  error: response.error || 'Unknown error',\n  message: response.message || 'Scrape endpoint returned an error'\n};\n\nconsole.error('\u274c Scrape failed:', JSON.stringify(error, null, 2));\n\nreturn [{ json: error }];"
      },
      "id": "log-failure",
      "name": "Log Failure",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        920,
        400
      ]
    }
  ],
  "connections": {
    "Every 2 Hours": {
      "main": [
        [
          {
            "node": "Trigger Scrape",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Scrape": {
      "main": [
        [
          {
            "node": "Check Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Success": {
      "main": [
        [
          {
            "node": "Log Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "Scheduled",
      "id": "scheduled"
    },
    {
      "name": "Scraping",
      "id": "scraping"
    }
  ],
  "triggerCount": 0,
  "updatedAt": "2024-01-05T00:00:00.000Z",
  "versionId": "1"
}