{
  "name": "Incremental Lead Sync",
  "nodes": [
    {
      "parameters": {
        "triggerTimes": [
          {
            "hour": 0,
            "minute": 0
          }
        ],
        "mode": "everyX"
      },
      "id": "Cron",
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        200,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "const lastRun = $json.lastRun || new Date(Date.now() - 3600000).toISOString();\nreturn [{ json: { updatedAfter: lastRun } }];"
      },
      "id": "SetWindow",
      "name": "Set Window",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        440,
        200
      ]
    },
    {
      "parameters": {
        "requestMethod": "GET",
        "url": "http://api:8080/v1/leads",
        "jsonParameters": true,
        "options": {
          "queryParameters": [
            {
              "name": "updatedAfter",
              "value": "={{$json.updatedAfter}}"
            }
          ],
          "headers": {
            "X-API-Key": "={{$env.API_DEV_KEY}}"
          }
        }
      },
      "id": "FetchLeads",
      "name": "Fetch Leads",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        680,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "body.items",
        "splitInto": "items"
      },
      "id": "SplitBatches",
      "name": "Split Batches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        920,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "// TODO: send each lead to destination (Sheets, database, etc.)\nreturn items;"
      },
      "id": "ProcessLead",
      "name": "Process Lead",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1160,
        200
      ]
    }
  ],
  "connections": {
    "Cron": {
      "main": [
        [
          {
            "node": "Set Window",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Window": {
      "main": [
        [
          {
            "node": "Fetch Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Leads": {
      "main": [
        [
          {
            "node": "Split Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Batches": {
      "main": [
        [
          {
            "node": "Process Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}