{
  "nodes": [
    {
      "id": "79eb3b2e-7039-4462-b63a-941a8b7ed5c5",
      "name": "List Beehiiv publications",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -684,
        -40
      ],
      "parameters": {
        "url": "https://api.beehiiv.com/v2/publications",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "495b8118-f0dc-442e-8b52-48cd3b698753",
      "name": "Add Beehiiv subscriber",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -464,
        -40
      ],
      "parameters": {
        "url": "=https://api.beehiiv.com/v2/publications/{ { $json.data[0].id } }/subscriptions",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "email",
              "value": "={ { $('Extract & Qualify').item.json.message.content.email } }"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "3ae5298e-c0bf-44ef-9f1b-d6f1b8964c73",
      "name": "Extract & Qualify",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -1060,
        -40
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are a lead qualification engine. You will receive the text of an email containing a form response.\n\nHere is the form response: \n{ { $json.text } } \n\nYour task is to evaluate the fields: \"email\", \"company name\", and \"website\" to determine if a lead is qualified, as well as extracting the rest of the variables in the form response to output a JSON with all the fields.\n\n\"isQualified\" → true or false\n\"reason\" → short explanation if unqualified, empty string if qualified\n\nRules:\n\nIf the email domain is from a free provider (e.g., gmail.com, yahoo.com, hotmail.com, outlook.com), set isQualified = false and set reason = \"Personal email used\".\n\nIf the website field is missing, invalid, or not a proper URL, set isQualified = false and set reason = \"Invalid or missing website\".\n\nIf both email and website are acceptable, set isQualified = true and set reason = \"\".\n\nResponse format: Only return JSON with all the variables. No explanations, no additional text."
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "e35a283f-7ddd-4d20-b3cb-2a2d57cb1a36",
      "name": "New form trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1280,
        -40
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "sender": "user@example.com"
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "172514fb-f8b5-4bf9-940c-edf115f6448d",
      "name": "insert in Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -244,
        -40
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={ { $('Extract & Qualify').item.json.message.content.name } }",
            "Role": "={ { $('Extract & Qualify').item.json.message.content.role } }",
            "Size": "={ { $('Extract & Qualify').item.json.message.content.companySize } }",
            "Email": "={ { $('Extract & Qualify').item.json.message.content.email } }",
            "Budget": "={ { $('Extract & Qualify').item.json.message.content.projectBudget } }",
            "Reason": "={ { $('Extract & Qualify').item.json.message.content.reason } }",
            "Company": "={ { $('Extract & Qualify').item.json.message.content.companyName } }",
            "Message": "={ { $('Extract & Qualify').item.json.message.content.howCanWeHelp } }",
            "Website": "={ { $('Extract & Qualify').item.json.message.content.companyWebsite } }",
            "Services": "={ { $('Extract & Qualify').item.json.message.content.servicesInterested } }",
            "Is Qualified": "={ { $('Extract & Qualify').item.json.message.content.isQualified } }"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Role",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Role",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Website",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Size",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Size",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Budget",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Budget",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Services",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Services",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Is Qualified",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Is Qualified",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reason",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "useAppend": true
        },
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1XpNF2nQfYkSCOYQbG-KR0PT3iisVyjO50p-GwhO_IMo/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1XpNF2nQfYkSCOYQbG-KR0PT3iisVyjO50p-GwhO_IMo",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1XpNF2nQfYkSCOYQbG-KR0PT3iisVyjO50p-GwhO_IMo/edit?usp=drivesdk",
          "cachedResultName": "Website form responses"
        }
      },
      "typeVersion": 4.5
    }
  ],
  "connections": {
    "New form trigger": {
      "main": [
        [
          {
            "node": "Extract & Qualify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "insert in Sheets": {
      "main": [
        []
      ]
    },
    "Extract & Qualify": {
      "main": [
        [
          {
            "node": "List Beehiiv publications",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Beehiiv subscriber": {
      "main": [
        [
          {
            "node": "insert in Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Beehiiv publications": {
      "main": [
        [
          {
            "node": "Add Beehiiv subscriber",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}