{
  "name": "EN — Client Onboarding → GHL",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "en-onboard",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000001",
      "name": "Onboarding Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "webhookId": "en-onboard"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://services.leadconnectorhq.com/contacts/upsert",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer pit-0947beb9-c594-4e74-865e-6b3ad8b562ef"
            },
            {
              "name": "Version",
              "value": "2021-07-28"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ locationId: '0e0axgfXYSsM0J690HlY', firstName: $json.body.first_name || '', lastName: $json.body.last_name || '', email: $json.body.email || undefined, phone: $json.body.phone || undefined, companyName: $json.body.biz_name || '', website: $json.body.website || '', source: 'Onboarding Form', tags: ['onboarded', 'new-client', ...($json.body.services ? $json.body.services.split(', ').filter(Boolean).map(s => 'service:' + s.toLowerCase().replace(/[^a-z0-9]+/g, '-')) : []), ...($json.body.platforms ? $json.body.platforms.split(', ').filter(Boolean).map(p => 'platform:' + p.toLowerCase().replace(/[^a-z0-9]+/g, '-')) : [])] }) }}",
        "options": {}
      },
      "id": "a1b2c3d4-0002-0002-0002-000000000002",
      "name": "GHL — Upsert Contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        500,
        160
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $json.contact.id }}/notes",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer pit-0947beb9-c594-4e74-865e-6b3ad8b562ef"
            },
            {
              "name": "Version",
              "value": "2021-07-28"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ body: ['📋 ONBOARDING FORM — ' + new Date($('Onboarding Webhook').item.json.body.submitted_at).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' }), '', 'BUSINESS', 'Company: ' + ($('Onboarding Webhook').item.json.body.biz_name || '—'), 'Niche: ' + ($('Onboarding Webhook').item.json.body.niche || '—'), 'Website: ' + ($('Onboarding Webhook').item.json.body.website || '—'), '', 'SERVICES REQUESTED', $('Onboarding Webhook').item.json.body.services || '—', '', 'PLATFORMS', $('Onboarding Webhook').item.json.body.platforms || '—', '', 'SOCIAL HANDLES', ...[$('Onboarding Webhook').item.json.body.ig ? 'Instagram: ' + $('Onboarding Webhook').item.json.body.ig : null, $('Onboarding Webhook').item.json.body.fb ? 'Facebook: ' + $('Onboarding Webhook').item.json.body.fb : null, $('Onboarding Webhook').item.json.body.tt ? 'TikTok: ' + $('Onboarding Webhook').item.json.body.tt : null, $('Onboarding Webhook').item.json.body.yt ? 'YouTube: ' + $('Onboarding Webhook').item.json.body.yt : null, $('Onboarding Webhook').item.json.body.li ? 'LinkedIn: ' + $('Onboarding Webhook').item.json.body.li : null, $('Onboarding Webhook').item.json.body.th ? 'Threads: ' + $('Onboarding Webhook').item.json.body.th : null, $('Onboarding Webhook').item.json.body.pi ? 'Pinterest: ' + $('Onboarding Webhook').item.json.body.pi : null, $('Onboarding Webhook').item.json.body.gb ? 'Google Business: ' + $('Onboarding Webhook').item.json.body.gb : null].filter(Boolean), '', 'GOALS & TRACKING', 'Primary Goal: ' + ($('Onboarding Webhook').item.json.body.primary_goal || '—'), 'Revenue Tracking: ' + ($('Onboarding Webhook').item.json.body.revenue_tracking || '—'), '', 'ADDITIONAL NOTES', $('Onboarding Webhook').item.json.body.notes || '—', '', 'CREDENTIALS', $('Onboarding Webhook').item.json.body.credentials_provided === 'yes' ? 'Client provided credentials — stored in EN Client Credentials sheet' : 'No credentials provided'].join('\\n') }) }}",
        "options": {}
      },
      "id": "a1b2c3d4-0003-0003-0003-000000000003",
      "name": "GHL — Create Note",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        760,
        160
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ok: true, contactId: $('GHL — Upsert Contact').item.json.contact.id }) }}",
        "options": {}
      },
      "id": "a1b2c3d4-0004-0004-0004-000000000004",
      "name": "Respond 200",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1020,
        160
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "cred-check",
              "leftValue": "={{ $json.body.credentials_provided }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a1b2c3d4-0005-0005-0005-000000000005",
      "name": "Has Credentials?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        500,
        460
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1RNQssJwYfCZyc6ZdQsftqy4UqsdhLb2v5svqVikEXoI",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Date Submitted": "={{ $('Onboarding Webhook').item.json.body.submitted_at }}",
            "Business Name": "={{ $('Onboarding Webhook').item.json.body.biz_name }}",
            "First Name": "={{ $('Onboarding Webhook').item.json.body.first_name }}",
            "Last Name": "={{ $('Onboarding Webhook').item.json.body.last_name }}",
            "Email": "={{ $('Onboarding Webhook').item.json.body.email }}",
            "Platforms": "={{ $('Onboarding Webhook').item.json.body.platforms }}",
            "Credentials (JSON)": "={{ $('Onboarding Webhook').item.json.body.credentials }}"
          }
        },
        "options": {}
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "OhjizsinSISmx4Gl",
          "name": "Google Sheets OAuth2 API"
        }
      },
      "id": "a1b2c3d4-0006-0006-0006-000000000006",
      "name": "Sheets — Log Credentials",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        760,
        460
      ]
    }
  ],
  "connections": {
    "Onboarding Webhook": {
      "main": [
        [
          {
            "node": "GHL — Upsert Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Has Credentials?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GHL — Upsert Contact": {
      "main": [
        [
          {
            "node": "GHL — Create Note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GHL — Create Note": {
      "main": [
        [
          {
            "node": "Respond 200",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Credentials?": {
      "main": [
        [
          {
            "node": "Sheets — Log Credentials",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
