{
  "name": "SRSv7 Skiptrace Engine v1.0",
  "nodes": [
    {
      "id": "SingleWebhook",
      "type": "n8n-nodes-base.webhook",
      "name": "Single Skiptrace Trigger",
      "position": [
        400,
        200
      ],
      "parameters": {
        "path": "skiptrace_single",
        "httpMethod": "POST",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "BatchWebhook",
      "type": "n8n-nodes-base.webhook",
      "name": "Batch Skiptrace Trigger",
      "position": [
        400,
        400
      ],
      "parameters": {
        "path": "skiptrace_batch",
        "httpMethod": "POST",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "NormalizeData",
      "type": "n8n-nodes-base.function",
      "name": "Normalize Input",
      "position": [
        700,
        300
      ],
      "parameters": {
        "functionCode": "const input = items[0].json;\n\n// Normalize Email\ninput.email = input.email ? input.email.toLowerCase().trim() : null;\n\n// Normalize Phone\nif (input.phone) {\n  input.phone = input.phone.replace(/[^0-9]/g, \"\");\n  if (input.phone.length === 11 && input.phone.startsWith(\"1\")) {\n    input.phone = input.phone.substring(1);\n  }\n}\n\n// Normalize Name\nif (input.full_name) {\n  const parts = input.full_name.trim().split(\" \");\n  input.first_name = parts[0];\n  input.last_name = parts[parts.length - 1];\n}\n\nreturn [{ json: input }];"
      }
    },
    {
      "id": "PDL_Request",
      "type": "n8n-nodes-base.httpRequest",
      "name": "PDL Lookup",
      "position": [
        1000,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "https://api.peopledatalabs.com/v5/person/enrich",
        "queryParametersUi": {
          "parameter": [
            {
              "name": "api_key",
              "value": "### INSERT_YOUR_PDL_API_KEY ###"
            },
            {
              "name": "email",
              "value": "={{$json.email}}"
            },
            {
              "name": "phone",
              "value": "={{$json.phone}}"
            }
          ]
        }
      }
    },
    {
      "id": "ScoreNode",
      "type": "n8n-nodes-base.function",
      "name": "Confidence Score",
      "position": [
        1300,
        300
      ],
      "parameters": {
        "functionCode": "const data = items[0].json;\n\nlet score = 0;\n\nif (data.full_name) score += 0.2;\nif (data.emails && data.emails.length > 0) score += 0.3;\nif (data.phone_numbers && data.phone_numbers.length > 0) score += 0.3;\nif (data.location_names && data.location_names.length > 0) score += 0.2;\n\nreturn [{ json: { match_score: score, pdl: data } }];"
      }
    },
    {
      "id": "Router",
      "type": "n8n-nodes-base.switch",
      "name": "Confidence Router",
      "position": [
        1600,
        300
      ],
      "parameters": {
        "property": "match_score",
        "rules": [
          {
            "value": 0.65,
            "operation": "gte"
          },
          {
            "value": 0.3,
            "operation": "gte"
          },
          {
            "value": 0.3,
            "operation": "lt"
          }
        ]
      }
    },
    {
      "id": "GHL_Update_Valid",
      "type": "n8n-nodes-base.httpRequest",
      "name": "Update GHL (Valid Match)",
      "position": [
        1900,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.gohighlevel.com/v1/contacts/### INSERT_YOUR_GHL_CONTACT_ID ###",
        "headers": {
          "Authorization": "Bearer ### INSERT_YOUR_GHL_API_KEY ###"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "skiptrace_status",
              "value": "valid_match"
            },
            {
              "name": "skiptrace_score",
              "value": "={{$json.match_score}}"
            }
          ]
        }
      }
    },
    {
      "id": "GHL_Update_Partial",
      "type": "n8n-nodes-base.httpRequest",
      "name": "Update GHL (Partial Match)",
      "position": [
        1900,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.gohighlevel.com/v1/contacts/### INSERT_YOUR_GHL_CONTACT_ID ###",
        "headers": {
          "Authorization": "Bearer ### INSERT_YOUR_GHL_API_KEY ###"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "skiptrace_status",
              "value": "partial_match"
            },
            {
              "name": "skiptrace_score",
              "value": "={{$json.match_score}}"
            }
          ]
        }
      }
    },
    {
      "id": "GHL_Update_NoMatch",
      "type": "n8n-nodes-base.httpRequest",
      "name": "Update GHL (Tier2 Required)",
      "position": [
        1900,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.gohighlevel.com/v1/contacts/### INSERT_YOUR_GHL_CONTACT_ID ###",
        "headers": {
          "Authorization": "Bearer ### INSERT_YOUR_GHL_API_KEY ###"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "skiptrace_status",
              "value": "no_match"
            },
            {
              "name": "skiptrace_score",
              "value": "={{$json.match_score}}"
            },
            {
              "name": "tags",
              "value": "tier2_required"
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Single Skiptrace Trigger": {
      "main": [
        [
          "Normalize Input"
        ]
      ]
    },
    "Batch Skiptrace Trigger": {
      "main": [
        [
          "Normalize Input"
        ]
      ]
    },
    "Normalize Input": {
      "main": [
        [
          "PDL Lookup"
        ]
      ]
    },
    "PDL Lookup": {
      "main": [
        [
          "Confidence Score"
        ]
      ]
    },
    "Confidence Score": {
      "main": [
        [
          "Confidence Router"
        ]
      ]
    },
    "Confidence Router": {
      "main": [
        [
          "Update GHL (Valid Match)"
        ],
        [
          "Update GHL (Partial Match)"
        ],
        [
          "Update GHL (Tier2 Required)"
        ]
      ]
    }
  }
}