{
  "updatedAt": "2026-03-31T04:38:23.580Z",
  "createdAt": "2026-03-31T03:55:25.925Z",
  "id": "iutnXdBIxewwjXIS",
  "name": "Infinite Nurture - Unsubscribe Sync",
  "description": null,
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "resend-webhook",
        "responseMode": "onReceived",
        "responseData": "allEntries",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Resend Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "resend-webhook"
    },
    {
      "parameters": {
        "jsCode": "// Parse Resend webhook event\nconst body = $input.first().json.body || $input.first().json;\nconst eventType = body.type || '';\nconst data = body.data || {};\nconst email = data.email || data.to?.[0] || '';\nconst reason = data.reason || eventType;\nconst timestamp = new Date().toISOString();\n\n// We care about: email.bounced, email.complained, contact.unsubscribed\nconst shouldTag = ['email.bounced', 'email.complained', 'contact.unsubscribed', 'email.delivery_delayed'].includes(eventType);\n\nreturn [{\n  json: {\n    eventType,\n    email,\n    reason,\n    timestamp,\n    shouldTag,\n    ghlTag: eventType === 'email.bounced' ? 'email_bounced' :\n            eventType === 'email.complained' ? 'email_complained' :\n            eventType === 'contact.unsubscribed' ? 'email_unsubscribed' :\n            'email_issue'\n  }\n}];"
      },
      "id": "code-parse",
      "name": "Parse Event",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        250,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "leftValue": "={{ $json.shouldTag }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "if-should-tag",
      "name": "Should Tag Contact?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        500,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://services.leadconnectorhq.com/contacts/search",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer pit-4e603453-ec66-4ab7-8e3a-a4af3cb56de7"
            },
            {
              "name": "Version",
              "value": "2021-07-28"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ locationId: 'VMK8SyHTd8uCMgcJ7I2A', filters: [{ field: 'email', operator: 'eq', value: $json.email }] }) }}",
        "options": {}
      },
      "id": "http-find-contact",
      "name": "Find Contact in GHL",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        750,
        -100
      ]
    },
    {
      "parameters": {
        "jsCode": "// Extract contact ID and prepare tag update\nconst response = $input.first().json;\nconst contacts = response.contacts || response.body?.contacts || [];\nconst tagInfo = $node['Parse Event'].json;\n\nif (contacts.length === 0) {\n  return [{ json: { found: false, email: tagInfo.email, error: 'Contact not found in GHL' } }];\n}\n\nconst contact = contacts[0];\nconst existingTags = contact.tags || [];\nconst newTag = tagInfo.ghlTag;\n\nif (existingTags.includes(newTag)) {\n  return [{ json: { found: true, alreadyTagged: true, contactId: contact.id, email: tagInfo.email } }];\n}\n\nreturn [{\n  json: {\n    found: true,\n    alreadyTagged: false,\n    contactId: contact.id,\n    email: tagInfo.email,\n    tags: [...existingTags, newTag],\n    newTag: newTag,\n    eventType: tagInfo.eventType\n  }\n}];"
      },
      "id": "code-prep-tag",
      "name": "Prep Tag Update",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1000,
        -100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "leftValue": "={{ $json.found }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            },
            {
              "leftValue": "={{ $json.alreadyTagged }}",
              "rightValue": false,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "if-needs-tag",
      "name": "Needs Tag Update?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1250,
        -100
      ]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $json.contactId }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer pit-4e603453-ec66-4ab7-8e3a-a4af3cb56de7"
            },
            {
              "name": "Version",
              "value": "2021-07-28"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ tags: $json.tags }) }}",
        "options": {}
      },
      "id": "http-tag-contact",
      "name": "Tag Contact in GHL",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1500,
        -200
      ]
    }
  ],
  "connections": {
    "Resend Webhook": {
      "main": [
        [
          {
            "node": "Parse Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Event": {
      "main": [
        [
          {
            "node": "Should Tag Contact?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Should Tag Contact?": {
      "main": [
        [
          {
            "node": "Find Contact in GHL",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Find Contact in GHL": {
      "main": [
        [
          {
            "node": "Prep Tag Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prep Tag Update": {
      "main": [
        [
          {
            "node": "Needs Tag Update?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs Tag Update?": {
      "main": [
        [
          {
            "node": "Tag Contact in GHL",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "staticData": null,
  "meta": null,
  "pinData": null,
  "versionId": "b0386db1-fa4d-4619-8e59-f40bcd52dc3d",
  "activeVersionId": null,
  "versionCounter": 2,
  "triggerCount": 0,
  "shared": [
    {
      "updatedAt": "2026-03-31T03:55:25.927Z",
      "createdAt": "2026-03-31T03:55:25.927Z",
      "role": "workflow:owner",
      "workflowId": "iutnXdBIxewwjXIS",
      "projectId": "91dLj8Hg37i136qG",
      "project": {
        "updatedAt": "2026-03-22T06:53:28.112Z",
        "createdAt": "2026-02-12T18:32:53.056Z",
        "id": "91dLj8Hg37i136qG",
        "name": "Bryce Folsom <bfolsom@emersonnorth.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "17d3676f-3e74-4586-8363-5c1f4d237ed7"
      }
    }
  ],
  "tags": [],
  "activeVersion": null
}