{
  "name": "Lead Status Update Based on Activity",
  "nodes": [
    {
      "parameters": {
        "url": "http://localhost:8000/api/activities",
        "authentication": "headerAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer={{$node[\"Set API Key\"].json[\"apiKey\"]}}"
            }
          ]
        },
        "options": {
          "queryParameters": {
            "parameters": [
              {
                "name": "completed",
                "value": "true"
              },
              {
                "name": "limit",
                "value": "50"
              }
            ]
          }
        }
      },
      "name": "Get Completed Activities",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "apiKey",
              "value": "YOUR_API_KEY_HERE"
            }
          ]
        }
      },
      "name": "Set API Key",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "Split Activities",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "url": "=http://localhost:8000/api/leads/{{$json[\"lead_id\"]}}",
        "authentication": "headerAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer={{$node[\"Set API Key\"].json[\"apiKey\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Get Lead Details",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"status\"]}}",
              "value2": "new",
              "operation": "equal"
            }
          ]
        }
      },
      "name": "IF Status is New",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "url": "=http://localhost:8000/api/leads/{{$json[\"id\"]}}",
        "authentication": "headerAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer={{$node[\"Set API Key\"].json[\"apiKey\"]}}"
            }
          ]
        },
        "options": {},
        "method": "PATCH",
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "status",
              "value": "contacted"
            }
          ]
        }
      },
      "name": "Update Lead Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1250,
        200
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      },
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        50,
        300
      ]
    }
  ],
  "connections": {
    "Get Completed Activities": {
      "main": [
        [
          {
            "node": "Split Activities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set API Key": {
      "main": [
        [
          {
            "node": "Get Completed Activities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Activities": {
      "main": [
        [
          {
            "node": "Get Lead Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Lead Details": {
      "main": [
        [
          {
            "node": "IF Status is New",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Status is New": {
      "main": [
        [
          {
            "node": "Update Lead Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set API Key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "versionId": "1",
  "id": "2",
  "tags": []
}