{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "d6992892-5eae-4c2f-8464-92e9b31a4a94",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        544,
        560
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "cb478ec2-ebb5-41be-b618-bdc2ea5c2673",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        496,
        96
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"Company\": [\"company1\", \"company2\"],\n\t\"Email\": [\"email1\", \"email2\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a182f54b-0b72-4814-838e-90bbb148e56e",
      "name": "Sticky Note59",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        -336
      ],
      "parameters": {
        "color": 7,
        "width": 2416,
        "height": 1056,
        "content": "### Research and log new business leads into Google Sheets (Perplexity + OpenAI + Google Sheets)\n\nAutomatically research new leads in your target area, structure the results with AI, and append them into Google Sheets \u2014 all orchestrated in n8n.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b82daab8-e6eb-4835-95a8-29453ee6a758",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1424,
        -336
      ],
      "parameters": {
        "width": 400,
        "height": 1056,
        "content": "\n## \ud83d\udee0\ufe0f Setup instructions\nFollow these sticky-note setup steps (already included in the workflow):\n\n### 1) Connect Google Sheets (OAuth2)\n1. In **n8n \u2192 Credentials \u2192 New \u2192 Google Sheets (OAuth2)**  \n2. Sign in with your Google account and grant access  \n3. In the Google Sheets node, select your **Spreadsheet** and **Worksheet**  \n\nExample sheet:  \nhttps://docs.google.com/spreadsheets/d/1MnaU8hSi8PleDNVcNnyJ5CgmDYJSUTsr7X5HIwa-MLk/edit#gid=0  \n\n---\n\n### 2) Connect Perplexity (API Key)\n1. Sign in at https://www.perplexity.ai/account  \n2. Generate an API key: https://docs.perplexity.ai/guides/getting-started  \n3. In **n8n \u2192 Credentials \u2192 New \u2192 Perplexity API**, paste your key  \n\n---\n\n### 3) Connect OpenAI (API Key)\n1. In **n8n \u2192 Credentials \u2192 New \u2192 OpenAI API**  \n2. Paste your **OpenAI API key**  \n3. In the **OpenAI Chat Model** node, select your credential and a **vision-capable model** (e.g., `gpt-4o-mini`, `gpt-4o`)  \n\n\n\n- \ud83d\udce7 **rbreen@ynteractive.com**  \n- \ud83d\udd17 **Robert Breen** \u2014 https://www.linkedin.com/in/robert-breen-29429625/  \n- \ud83c\udf10 **ynteractive.com** \u2014 https://ynteractive.com\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "efedcf0f-7cfe-4cab-9861-b8c8738df238",
      "name": "Sticky Note71",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 688,
        "content": "### 2)To set up credentials for the Perplexity API in n8n, follow these steps:\n\nObtain your Perplexity API key:\n\nSign in to your Perplexity account at https://www.perplexity.ai/account.\nFollow the instructions in the Perplexity API getting started guide to generate an API key: https://docs.perplexity.ai/guides/getting-started.\nIn n8n:\n\nGo to \"Credentials\" in the left sidebar.\nClick \"New credential\" and search for \"Perplexity\".\nSelect the \"Perplexity API\" credential type.\nEnter your API key in the required field.\nSave the credential."
      },
      "typeVersion": 1
    },
    {
      "id": "7a45cba3-0045-4809-a987-767133e667e1",
      "name": "Sticky Note72",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        -112
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 656,
        "content": "### 1) Connect Google Sheets (OAuth2)\n1. In **n8n \u2192 Credentials \u2192 New \u2192 Google Sheets (OAuth2)**  \n2. Sign in with your Google account and grant access  \n3. In each Google Sheets node, select your **Spreadsheet** and the appropriate **Worksheet**:  \n\n\nhttps://docs.google.com/spreadsheets/d/1MnaU8hSi8PleDNVcNnyJ5CgmDYJSUTsr7X5HIwa-MLk/edit#gid=0"
      },
      "typeVersion": 1
    },
    {
      "id": "0b0d1e8c-0557-43f5-a15b-5355cfc7749b",
      "name": "Sticky Note69",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        272
      ],
      "parameters": {
        "color": 3,
        "width": 214,
        "height": 400,
        "content": "### 3) Connect OpenAI (API Key)\n1. In **n8n \u2192 Credentials \u2192 New \u2192 OpenAI API**  \n2. Paste your **OpenAI API key**  \n3. In **OpenAI Chat Model**, select your credential and a **vision-capable** chat model (e.g., `gpt-4o-mini`, `gpt-4o`, or your configured vision model)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5128ea0a-8d3d-49d1-bba2-102881725941",
      "name": "Start Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -944,
        16
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "936c89eb-8d98-4c03-952e-14754503f71d",
      "name": "Set Location",
      "type": "n8n-nodes-base.set",
      "position": [
        -736,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7fa935ba-7bb5-47f0-8b45-d5bbd054a3a3",
              "name": "Area",
              "type": "string",
              "value": "Hershey PA"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f4fb7a37-a9cd-4c03-9c6e-3a4faf94f50a",
      "name": "Get Current Leads",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -480,
        352
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.Area }}",
              "lookupColumn": "Area"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_AWS_SECRET_KEY_HERE-MLk/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_AWS_SECRET_KEY_HERE-MLk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_AWS_SECRET_KEY_HERE-MLk/edit?usp=drivesdk",
          "cachedResultName": "Perplexity Leads"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "eb5c203e-e317-4e1e-ae13-2c69eaa2bb95",
      "name": "Combine Into One",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -224,
        32
      ],
      "parameters": {
        "options": {
          "includeBinaries": true
        },
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "869e140c-1d03-4ecf-a8a1-e999b98643f7",
      "name": "Set as text",
      "type": "n8n-nodes-base.set",
      "position": [
        -64,
        -224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "889ed2f4-ac57-4786-8a7d-da2621f49c50",
              "name": "Search Area",
              "type": "string",
              "value": "={{ $('Set Location').item.json.Area }}"
            },
            {
              "id": "e59a6822-a279-40a7-9894-99e4e1feab37",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c52018ce-f30a-4f0a-9a56-bc517b317972",
      "name": "Research Leads",
      "type": "n8n-nodes-base.perplexity",
      "position": [
        64,
        560
      ],
      "parameters": {
        "model": "sonar",
        "options": {},
        "messages": {
          "message": [
            {
              "role": "system",
              "content": "Research 20 coffee shops near the area. Output only the company name and the email address for each. Do not include businesses already scraped. "
            },
            {
              "content": "=Area:  {{ $json['Search Area'] }}\nAlready Scraped: {{ $json.data }}"
            }
          ]
        },
        "simplify": true,
        "requestOptions": {}
      },
      "credentials": {
        "perplexityApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5a963448-24e1-4519-9448-a388edd9105e",
      "name": "Write JSON",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        304,
        -128
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "Convert this to json. \n\nNeed a record for each email address with the name of the company. if null show blank\n\noutput like this. \n\n{\n\t\"Company\": [\"company1\", \"company2\"],\n\t\"Email\": [\"email1\", \"email2\"]\n}\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "c1754baf-e288-4268-9626-24a5741d35f8",
      "name": "Split Companies",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        768,
        -192
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output.Company"
      },
      "typeVersion": 1
    },
    {
      "id": "c1d17999-2e4a-46e4-8a13-fe0dffc9c646",
      "name": "Split Emails",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        768,
        48
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output.Email"
      },
      "typeVersion": 1
    },
    {
      "id": "78ee113d-582e-4ad5-b15b-1504aa1747cb",
      "name": "Merge Rows",
      "type": "n8n-nodes-base.merge",
      "position": [
        960,
        -48
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "1bd2c56a-9c1f-4436-89f7-04bad3acd0c0",
      "name": "Send Leads to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1152,
        176
      ],
      "parameters": {
        "columns": {
          "value": {
            "Area": "={{ $('Set as text').item.json['Search Area'] }}",
            "Email": "={{ $json['output.Email'] }}",
            "Company": "={{ $json['output.Company'] }}"
          },
          "schema": [
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Area",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Area",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_AWS_SECRET_KEY_HERE-MLk/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_AWS_SECRET_KEY_HERE-MLk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_AWS_SECRET_KEY_HERE-MLk/edit?usp=drivesdk",
          "cachedResultName": "Perplexity Leads"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "connections": {
    "Merge Rows": {
      "main": [
        [
          {
            "node": "Send Leads to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write JSON": {
      "main": [
        [
          {
            "node": "Split Companies",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set as text": {
      "main": [
        [
          {
            "node": "Research Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Location": {
      "main": [
        [
          {
            "node": "Get Current Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Emails": {
      "main": [
        [
          {
            "node": "Merge Rows",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Research Leads": {
      "main": [
        [
          {
            "node": "Write JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Workflow": {
      "main": [
        [
          {
            "node": "Set Location",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Companies": {
      "main": [
        [
          {
            "node": "Merge Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Into One": {
      "main": [
        [
          {
            "node": "Set as text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Leads": {
      "main": [
        [
          {
            "node": "Combine Into One",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Write JSON",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Write JSON",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}