{
  "name": "GoHighLevel Lead Flow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ghl-webhook",
        "options": {
          "responseMode": "responseNode"
        }
      },
      "id": "webhook-trigger",
      "name": "GHL Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        400
      ],
      "notes": "Configure this webhook URL in your GoHighLevel account to receive lead notifications"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "lead-id",
              "name": "leadId",
              "value": "={{ $json.body.contact?.id || $json.body.id }}",
              "type": "string"
            },
            {
              "id": "lead-name",
              "name": "leadName",
              "value": "={{ $json.body.contact?.name || ($json.body.firstName + ' ' + $json.body.lastName) }}",
              "type": "string"
            },
            {
              "id": "lead-email",
              "name": "leadEmail",
              "value": "={{ $json.body.contact?.email || $json.body.email }}",
              "type": "string"
            },
            {
              "id": "lead-phone",
              "name": "leadPhone",
              "value": "={{ $json.body.contact?.phone || $json.body.phone }}",
              "type": "string"
            },
            {
              "id": "lead-source",
              "name": "leadSource",
              "value": "={{ $json.body.source || 'GHL' }}",
              "type": "string"
            },
            {
              "id": "lead-status",
              "name": "leadStatus",
              "value": "={{ $json.body.status || 'new' }}",
              "type": "string"
            },
            {
              "id": "timestamp",
              "name": "timestamp",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            },
            {
              "id": "tags",
              "name": "tags",
              "value": "={{ $json.body.tags || [] }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "id": "normalize-lead-data",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        460,
        400
      ],
      "notes": "Standardize incoming lead data structure"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "email-exists",
              "leftValue": "={{ $json.leadEmail }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists"
              }
            },
            {
              "id": "email-valid",
              "leftValue": "={{ $json.leadEmail }}",
              "rightValue": "@",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "validate-lead-data",
      "name": "Validate Lead Data",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        680,
        400
      ],
      "notes": "Ensure lead has valid email before processing"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "high-value-check",
              "leftValue": "={{ $json.tags }}",
              "rightValue": "high-value",
              "operator": {
                "type": "array",
                "operation": "contains"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "route-by-priority",
      "name": "Route by Priority",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        900,
        400
      ],
      "notes": "Route high-value leads to priority queue"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.example-crm.com/leads",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "contact_id",
              "value": "={{ $json.leadId }}"
            },
            {
              "name": "name",
              "value": "={{ $json.leadName }}"
            },
            {
              "name": "email",
              "value": "={{ $json.leadEmail }}"
            },
            {
              "name": "phone",
              "value": "={{ $json.leadPhone }}"
            },
            {
              "name": "source",
              "value": "={{ $json.leadSource }}"
            },
            {
              "name": "priority",
              "value": "high"
            }
          ]
        },
        "options": {}
      },
      "id": "send-to-priority-crm",
      "name": "Send to Priority CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "notes": "Send high-priority leads to CRM immediately"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.example-crm.com/leads",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "contact_id",
              "value": "={{ $json.leadId }}"
            },
            {
              "name": "name",
              "value": "={{ $json.leadName }}"
            },
            {
              "name": "email",
              "value": "={{ $json.leadEmail }}"
            },
            {
              "name": "phone",
              "value": "={{ $json.leadPhone }}"
            },
            {
              "name": "source",
              "value": "={{ $json.leadSource }}"
            },
            {
              "name": "priority",
              "value": "normal"
            }
          ]
        },
        "options": {}
      },
      "id": "send-to-standard-crm",
      "name": "Send to Standard CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        500
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "notes": "Send standard leads to CRM with normal priority"
    },
    {
      "parameters": {
        "content": "\ud83d\ude80 High Priority Lead Received!\n\n**Name**: {{ $json.leadName }}\n**Email**: {{ $json.leadEmail }}\n**Phone**: {{ $json.leadPhone }}\n**Source**: {{ $json.leadSource }}\n**Time**: {{ $json.timestamp }}",
        "options": {}
      },
      "id": "notify-priority-lead",
      "name": "Notify Priority Lead",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1340,
        300
      ],
      "notes": "Replace with Slack, SMS, or Email notification for high-priority leads"
    },
    {
      "parameters": {
        "content": "\ud83d\udccb New Lead Received\n\n**Name**: {{ $json.leadName }}\n**Email**: {{ $json.leadEmail }}\n**Phone**: {{ $json.leadPhone }}\n**Source**: {{ $json.leadSource }}\n**Time**: {{ $json.timestamp }}",
        "options": {}
      },
      "id": "log-standard-lead",
      "name": "Log Standard Lead",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1340,
        500
      ],
      "notes": "Replace with logging or notification service"
    },
    {
      "parameters": {
        "content": "\u274c Invalid Lead Data Received\n\n**Reason**: Missing or invalid email\n**Data**: {{ JSON.stringify($json) }}\n**Time**: {{ $now.toISO() }}",
        "options": {}
      },
      "id": "log-invalid-lead",
      "name": "Log Invalid Lead",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        900,
        600
      ],
      "notes": "Log or notify about invalid lead data"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"status\": \"success\", \"message\": \"Lead received and processed\", \"leadId\": $json.leadId } }}",
        "options": {}
      },
      "id": "webhook-response-success",
      "name": "Webhook Response Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1560,
        400
      ],
      "notes": "Send success response back to GHL"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseCode": 400,
        "responseBody": "={{ { \"status\": \"error\", \"message\": \"Invalid lead data - missing required fields\" } }}",
        "options": {}
      },
      "id": "webhook-response-error",
      "name": "Webhook Response Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        700
      ],
      "notes": "Send error response back to GHL"
    }
  ],
  "connections": {
    "GHL Webhook Trigger": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "Validate Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Lead Data": {
      "main": [
        [
          {
            "node": "Route by Priority",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Invalid Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Priority": {
      "main": [
        [
          {
            "node": "Send to Priority CRM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send to Standard CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to Priority CRM": {
      "main": [
        [
          {
            "node": "Notify Priority Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to Standard CRM": {
      "main": [
        [
          {
            "node": "Log Standard Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Priority Lead": {
      "main": [
        [
          {
            "node": "Webhook Response Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Standard Lead": {
      "main": [
        [
          {
            "node": "Webhook Response Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Invalid Lead": {
      "main": [
        [
          {
            "node": "Webhook Response Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1.0.0",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "id": "ghl-lead-flow-template",
  "tags": [
    {
      "createdAt": "2024-01-01T00:00:00.000Z",
      "updatedAt": "2024-01-01T00:00:00.000Z",
      "id": "gohighlevel",
      "name": "GoHighLevel"
    },
    {
      "createdAt": "2024-01-01T00:00:00.000Z",
      "updatedAt": "2024-01-01T00:00:00.000Z",
      "id": "lead-management",
      "name": "Lead Management"
    },
    {
      "createdAt": "2024-01-01T00:00:00.000Z",
      "updatedAt": "2024-01-01T00:00:00.000Z",
      "id": "crm",
      "name": "CRM"
    }
  ]
}