{
  "nodes": [
    {
      "id": "0377cde7-39de-4a27-9f57-2ac62ecae89c",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -2520,
        400
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ac9d9f3b-db6c-4491-a1ce-ebfff9652ea3",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -700,
        780
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a05ec908-7476-49ec-9b32-3355cec11dce",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -580,
        780
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"email\": \"emailaddress\"\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "f6bbdf13-a0c1-4d9e-9157-c1a55a06e16b",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "onError": "continueRegularOutput",
      "position": [
        -1160,
        260
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "2003373e-cb00-4c74-b0bf-7ddb677ddb96",
      "name": "Execute Workflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "onError": "continueRegularOutput",
      "position": [
        -640,
        200
      ],
      "parameters": {
        "options": {
          "waitForSubWorkflow": false
        },
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "SDMXLfMXOQ6TDfKq",
          "cachedResultName": "Email Extraction Project"
        },
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "17c39dd5-5c44-4b95-ad50-591224d5517c",
      "name": "Extract Search Terms",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -2300,
        400
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o/edit#gid=0",
          "cachedResultName": "Searches"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o/edit?usp=drivesdk",
          "cachedResultName": "Searches&Results"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.6
    },
    {
      "id": "4222fa4d-d0e0-4e91-90bf-dead1424ed2c",
      "name": "Keep Unprocessed Rows",
      "type": "n8n-nodes-base.filter",
      "position": [
        -2080,
        400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c295c5ea-1ec4-4c9f-bf12-f4c23c60543f",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.Complete }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4de8ae34-2fea-4169-ada9-80cad9ee2e87",
      "name": "Filter to first row",
      "type": "n8n-nodes-base.code",
      "position": [
        -1860,
        400
      ],
      "parameters": {
        "jsCode": "return [items[0]];"
      },
      "typeVersion": 2
    },
    {
      "id": "af38c3a1-1414-4dcf-932d-e4a1db059a91",
      "name": "Mark Row as Completed",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1640,
        300
      ],
      "parameters": {
        "columns": {
          "value": {
            "Search": "={{ $json.Search }}",
            "Complete": "Yes"
          },
          "schema": [
            {
              "id": "Search",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Search",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Area",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Area",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Area Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Area Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Complete",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Complete",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Search"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o/edit#gid=0",
          "cachedResultName": "Searches"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o/edit?usp=drivesdk",
          "cachedResultName": "Searches&Results"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "e0087b09-f158-4ce8-bb74-ce45b5d9dfa6",
      "name": "Search Google Maps",
      "type": "n8n-nodes-serpapi.serpApi",
      "onError": "continueRegularOutput",
      "position": [
        -1640,
        500
      ],
      "parameters": {
        "q": "={{ $json.Search }}",
        "ll": "={{ $json.Area }}",
        "operation": "google_maps",
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fc558eef-8092-42f7-ab51-41c7002cb50b",
      "name": "Format output as table",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        -1420,
        500
      ],
      "parameters": {
        "jsCode": "const results = items[0].json.local_results || [];\n\nconst parsedResults = results.map(entry => {\n  // Remove \"/url?q=\" if present in the website\n  let cleanWebsite = entry.website || null;\n  if (cleanWebsite && cleanWebsite.startsWith(\"/url?q=\")) {\n    cleanWebsite = cleanWebsite.replace(\"/url?q=\", \"\").split(\"&\")[0];\n  }\n\n  return {\n    title: entry.title || null,\n    website: cleanWebsite,\n    address: entry.address || null,\n    phone: entry.phone || null,\n  };\n});\n\n// Return each result as a separate item\nreturn parsedResults.map(result => ({ json: result }));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "2d3fa5a3-f338-4eb8-be95-c915ce3f189a",
      "name": "Save Emails to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueRegularOutput",
      "position": [
        -940,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "Area": "={{ $('Extract Search Terms').item.json.Area }}",
            "phone": "={{ $('Format output as table').item.json.phone }}",
            "title": "={{ $('Format output as table').item.json.title }}",
            "Search": "={{ $('Extract Search Terms').item.json.Search }}",
            "address": "={{ $('Format output as table').item.json.address }}",
            "website": "={{ $('Format output as table').item.json.website }}",
            "Search Name": "={{ $('Extract Search Terms').item.json['Area Name'] }}",
            "email (Manual Entry)": "={{ $json.output.email }}"
          },
          "schema": [
            {
              "id": "title",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "website",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "address",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Search",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Search",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Search Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Search Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Area",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Area",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email (Manual Entry)",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email (Manual Entry)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "title"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1470668196,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o/edit#gid=1470668196",
          "cachedResultName": "Results"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nwgaTyp239ErzFS0IaDnJca-6LkIqvshmiHHs5bX77o/edit?usp=drivesdk",
          "cachedResultName": "Searches&Results"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "947fad74-dd81-4993-947e-a1e9264c1056",
      "name": "Scrape Web Page",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -940,
        400
      ],
      "parameters": {
        "url": "=https://api.apify.com/v2/acts/6sigmag~fast-website-content-crawler/run-sync-get-dataset-items\n",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"startUrls\": [\n        \"{{ $json.website }}\"\n    ]\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth"
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "eaab5179-b3a7-4c94-b2b9-0db29509573f",
      "name": "Extract Email - AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueRegularOutput",
      "position": [
        -720,
        560
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "extract the email address from the text. if there is no email address, output null. "
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "4a9f36d4-fd8b-409c-a1af-6be7248ed671",
      "name": "Reduce to 1 row",
      "type": "n8n-nodes-base.summarize",
      "onError": "continueRegularOutput",
      "position": [
        -940,
        200
      ],
      "parameters": {
        "options": {},
        "fieldsToSummarize": {
          "values": [
            {
              "field": "title"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "0fa2b9a4-3e33-4830-86a5-5466f4b9ab1a",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2380,
        20
      ],
      "parameters": {
        "width": 980,
        "content": "## n8n Workflow: Local Business Contact Finder with Email Extraction\n\n** Feel free to contact me if you need help implementing (rbreen@ynteractive.com) **"
      },
      "typeVersion": 1
    },
    {
      "id": "72de7718-1d85-47e4-ab0b-5e559323f6d4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3360,
        -80
      ],
      "parameters": {
        "width": 780,
        "height": 1160,
        "content": "## How to Implement This n8n Workflow\n\nFollow the steps below to get this business contact finder workflow up and running in your own environment:\n\n1. Copy the Google Sheet\nMake a copy of the search input/output sheet to your own Google Drive:\n\n\ud83d\udc49 https://docs.google.com/spreadsheets/d/1QgcVMlXRlM_5ZFFUHr6bVK-93Tzia9XseTX03ZYnowI/edit?usp=sharing\n\n2. Update the Google Sheets Nodes\nOpen the workflow in n8n.\n\nUpdate both Google Sheets nodes (\"Extract Search Terms\" and \"Save Emails to Sheet\") to point to your copied sheet.\n\nMake sure you select the correct sheet/tab names (Searches and Results).\n\nConnect your Google account using the Google Sheets OAuth2 credentials.\n\n3. Get a SerpAPI Key\nSign up for a free trial at \ud83d\udc49 https://serpapi.com/dashboard\n\nCopy your API key.\n\nIn the \u201cSearch Google Maps\u201d node:\n\nClick on credentials.\n\nAdd a new SerpAPI credential using your API key.\n\n4. Set Up Apify Crawler\nSign up for an Apify account at \ud83d\udc49 https://apify.com\n\nGo to the Actors section and add Fast Website Content Crawler to your account.\n\nIn the \"Scrape Web Page\" HTTP node:\n\nUnder credentials, enter your Apify API key as a query string parameter (token=YOUR_API_KEY).\n\n5. Add Your OpenAI Key\nSign up at \ud83d\udc49 https://platform.openai.com/\n\nGo to API keys and copy your secret key.\n\nIn the \"AI Agent\" (LangChain node) and \"OpenAI Chat Model\" nodes:\n\nAdd your OpenAI key under the OpenAI credentials section.\n\n\u2705 Once Complete:\nClick \"Execute Workflow\" to run the automation. The script will:\n\nRead a search + location from your Google Sheet.\n\nPull business info from Google Maps.\n\nVisit each business\u2019s website and scrape its content.\n\nUse AI to extract an email address if available.\n\nSave the full results into the \"Results\" tab and mark the search as complete.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c771ab3b-428f-46d9-be51-6ea1ce2a3659",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2560,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 2260,
        "height": 1160,
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Save Emails to Sheet",
            "type": "main",
            "index": 0
          },
          {
            "node": "Reduce to 1 row",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Scrape Web Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reduce to 1 row": {
      "main": [
        [
          {
            "node": "Execute Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Web Page": {
      "main": [
        [
          {
            "node": "Extract Email - AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Email - AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Search Google Maps": {
      "main": [
        [
          {
            "node": "Format output as table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter to first row": {
      "main": [
        [
          {
            "node": "Mark Row as Completed",
            "type": "main",
            "index": 0
          },
          {
            "node": "Search Google Maps",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Search Terms": {
      "main": [
        [
          {
            "node": "Keep Unprocessed Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep Unprocessed Rows": {
      "main": [
        [
          {
            "node": "Filter to first row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format output as table": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Email - AI Agent": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Extract Email - AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Extract Search Terms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}