{
  "name": "Sync Local Falcon rankings to BigQuery data warehouse",
  "nodes": [
    {
      "parameters": {
        "content": "## Sync Local Falcon Rankings to BigQuery Data Warehouse\n\n**Who is this for:** Data teams who want to centralize ranking data in BigQuery for advanced analytics, ML, and BI tools.\n\n**What this workflow does:**\n1. Fetches scan reports from Local Falcon\n2. Transforms data into BigQuery-compatible format\n3. Inserts records into your BigQuery table\n4. Maintains historical data for trend analysis\n\n**How to set up:**\n1. Add your Local Falcon API credentials (get your key at https://www.localfalcon.com/api/credentials)\n2. Add your Google Cloud credentials with BigQuery access\n3. Create a BigQuery dataset and table with schema\n4. Update project, dataset, and table IDs\n5. Activate the workflow\n\n**BigQuery Schema:**\n```sql\nCREATE TABLE rankings (\n  place_id STRING,\n  location_name STRING,\n  keyword STRING,\n  avg_rank FLOAT64,\n  platform STRING,\n  scan_date TIMESTAMP,\n  report_key STRING,\n  ingested_at TIMESTAMP\n);\n```\n\n**Requirements:**\n- Local Falcon account with API access\n- Google Cloud project with BigQuery enabled\n- Service account with BigQuery Data Editor role",
        "height": 580,
        "width": 460,
        "color": 5
      },
      "id": "sticky-main",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        100,
        -220
      ]
    },
    {
      "parameters": {
        "content": "### Step 1: Schedule\nRuns daily to sync data.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        40,
        660
      ]
    },
    {
      "parameters": {
        "content": "### Step 2: Get Reports\nFetches ranking data.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        660
      ]
    },
    {
      "parameters": {
        "content": "### Step 3: Transform\nFormats for BigQuery schema.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        660
      ]
    },
    {
      "parameters": {
        "content": "### Step 4: Insert\nLoads data into BigQuery.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step4",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        820,
        660
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 5
            }
          ]
        }
      },
      "id": "schedule",
      "name": "Every Day 5am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        140,
        440
      ]
    },
    {
      "parameters": {
        "resource": "scan",
        "operation": "listReports",
        "additionalFields": {
          "limit": 200
        }
      },
      "id": "get-reports",
      "name": "Get Scan Reports",
      "type": "@local-falcon/n8n-nodes-localfalcon.localFalcon",
      "typeVersion": 1,
      "position": [
        400,
        440
      ],
      "credentials": {
        "localFalconApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const reports = $input.first().json.reports || [];\nconst now = new Date().toISOString();\n\nreturn reports.map(report => ({\n  json: {\n    place_id: report.place_id || '',\n    location_name: report.location_name || 'Unknown',\n    keyword: report.keyword || '',\n    avg_rank: parseFloat(report.avg_rank) || null,\n    platform: report.platform || 'google',\n    scan_date: report.scan_date || now,\n    report_key: report.report_key || '',\n    ingested_at: now\n  }\n}));"
      },
      "id": "transform",
      "name": "Transform for BigQuery",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        440
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "projectId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GCP_PROJECT_ID"
        },
        "datasetId": {
          "__rl": true,
          "mode": "id",
          "value": "local_falcon_data"
        },
        "tableId": {
          "__rl": true,
          "mode": "id",
          "value": "rankings"
        },
        "columns": "*",
        "options": {}
      },
      "id": "insert-bq",
      "name": "Insert to BigQuery",
      "type": "n8n-nodes-base.googleBigQuery",
      "typeVersion": 2,
      "position": [
        920,
        440
      ],
      "credentials": {
        "googleBigQueryOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Every Day 5am": {
      "main": [
        [
          {
            "node": "Get Scan Reports",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Scan Reports": {
      "main": [
        [
          {
            "node": "Transform for BigQuery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transform for BigQuery": {
      "main": [
        [
          {
            "node": "Insert to BigQuery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}