{
  "id": "bCzsdWA9ELzYNPUy",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Lead Workflow: Yelp & Trustpilot Scraping + OpenAI Analysis via BrightData",
  "tags": [],
  "nodes": [
    {
      "id": "607d9645-e0ef-47a3-985d-15b50ffc522a",
      "name": "Form Trigger - Get User Input",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -640,
        -3320
      ],
      "parameters": {
        "options": {},
        "formTitle": "YelpDataScraper",
        "formFields": {
          "values": [
            {
              "fieldLabel": "country"
            },
            {
              "fieldLabel": "category "
            },
            {
              "fieldLabel": "location"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "80bd12f9-5fd0-4255-9834-d80838dfcba2",
      "name": "AI Location Analyzer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -340,
        -3460
      ],
      "parameters": {
        "text": "=You are an intelligent assistant helping to guide in location like i will give me some details like country location and business category so what you have to do give me some location names based in location (city).\n\nhere are some details:\n- Country: {{ $json.country }}\n- Location: {{ $json.location }}\n- Category: {{ $json['category '] }}\n\nnow analyse this city and find some sub placeces in this city and give me their name commas seperated for example we have a city Fort Worth so in Fort Worth there are many famous location or areas so you have to give some location and area name in this city.\n\n- ouput should be comma seperated.\n- do not include intro outro supporting text.\n- dont use special characters like $,*,# and more.",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "7b6d4d3d-a76e-4b2f-8e75-d4a68da0b572",
      "name": "Split Sub-locations",
      "type": "n8n-nodes-base.code",
      "position": [
        160,
        -3520
      ],
      "parameters": {
        "jsCode": "// Get the input data\nconst category = $('Form Trigger - Get User Input').first().json['category '];\nconst country = $('Form Trigger - Get User Input').first().json.country;\nconst aiOutput = $input.first().json.output;\n\n// Clean and split the AI output to get individual locations\nconst locationsString = aiOutput.replace(/[{}]/g, '').trim(); // Remove curly braces\nconst locations = locationsString\n  .split(',')\n  .map(location => location.trim())\n  .filter(location => location.length > 0); // Remove empty strings\n\n// Create output array with each location as a separate item\nconst output = locations.map((location, index) => {\n  return {\n    id: index + 1,\n    category: category,\n    country: country,\n    location: location\n  };\n});\n\n// Return the transformed data\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "a82eeee9-66df-45ce-8604-4685bab3a67f",
      "name": "Loop Yelp Locations",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        460,
        -3520
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "304e8b0e-6c0d-48aa-b67a-2f37dd5a2c49",
      "name": "Yelp Scraper",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        560,
        -3360
      ],
      "parameters": {
        "url": "https://api.brightdata.com/datasets/v3/trigger",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"input\": [\n    {\n      \"country\": \"{{ $json.country }}\",\n      \"location\": \"{{ $json.location }}\",\n      \"category\": \"{{ $json.category }}\"\n    }\n  ],\n  \"custom_output_fields\": [\n    \"name\",\n    \"overall_rating\",\n    \"reviews_count\",\n    \"categories\",\n    \"website\",\n    \"phone_number\",\n    \"address\",\n    \"url\"\n  ]\n}\n",
        "sendBody": true,
        "sendQuery": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "queryParameters": {
          "parameters": [
            {
              "name": "dataset_id",
              "value": "gd_lgugwl0519h1p14rwk"
            },
            {
              "name": "include_errors",
              "value": "true"
            },
            {
              "name": "type",
              "value": "discover_new"
            },
            {
              "name": "discover_by",
              "value": "search_filters"
            },
            {
              "name": "limit_per_input",
              "value": "10"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2afb35ee-9881-4bff-9267-eb754203e232",
      "name": "Check Yelp Scrape Progress",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        760,
        -3360
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/progress/{{ $json.snapshot_id }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "892f2e2e-9171-4c87-99e3-468c4621ee28",
      "name": "Wait (1 min) Yelp Completion",
      "type": "n8n-nodes-base.wait",
      "position": [
        960,
        -3360
      ],
      "parameters": {
        "unit": "minutes",
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "a2deac3d-eb34-49bd-9c1b-f940ec59887b",
      "name": "Verify Yelp Ready",
      "type": "n8n-nodes-base.if",
      "position": [
        1200,
        -3360
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "35ed620d-b5d5-4e97-bcc5-52b283d85616",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "ready"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3557f70e-29e6-4655-919a-997b9b905450",
      "name": "If Yelp Has Records",
      "type": "n8n-nodes-base.if",
      "position": [
        1420,
        -3380
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "80b55138-4007-47ce-9e4a-bf001c875047",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.records }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "53b7ba95-719c-4161-a8c2-ccd45aaa9768",
      "name": "Fetch Yelp Results",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1660,
        -3400
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/snapshot/{{ $json.snapshot_id }}",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "430f7f49-c0b8-4e0e-b217-d5b5831062e0",
      "name": "Save Yelp Data to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1820,
        -3260
      ],
      "parameters": {
        "columns": {
          "value": {
            "URL": "={{ $json.url }}",
            "name": "={{ $json.name }}",
            "address": "={{ $json.address }}",
            "Phone No": "={{ $json.phone_number }}",
            "categories": "={{ $json.categories }}",
            "overall_rating": "={{ $json.name }}",
            "Company Website": "={{ $json.website }}"
          },
          "schema": [
            {
              "id": "overall_rating",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "overall_rating",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "URL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "categories",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "categories",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone No",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone No",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "address",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Website",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hJD3mDpa93IvPrnvo29FFfqQWEAjGHA_wGG5hfIlqlk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit?usp=drivesdk",
          "cachedResultName": "Lead Generator Finder"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "70d7b107-8722-4269-8aaa-40c1c2f01ad6",
      "name": "Clean Unique Websites",
      "type": "n8n-nodes-base.code",
      "position": [
        1760,
        -3540
      ],
      "parameters": {
        "jsCode": "// Set to collect unique non-empty websites\nconst websites = new Set();\n\nfor (const item of items) {\n  const website = item.json[\"Company Website\"];\n  if (website && website.toString().trim() !== \"\") {\n    websites.add(website.toString().trim());\n  }\n}\n\n// Return one item per website\nreturn Array.from(websites).map(site => {\n  return {\n    json: {\n      website: site\n    }\n  };\n});\n"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "1fa4c014-2c1b-4d9a-978f-cf16423fc88d",
      "name": "Read Yelp Sheet Websites",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2020,
        -3540
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hJD3mDpa93IvPrnvo29FFfqQWEAjGHA_wGG5hfIlqlk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit?usp=drivesdk",
          "cachedResultName": "Lead Generator Finder"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6,
      "alwaysOutputData": true
    },
    {
      "id": "092a5d61-79a4-4a73-8633-05d2a6482efc",
      "name": "Make Trustpilot URLs",
      "type": "n8n-nodes-base.code",
      "position": [
        2200,
        -3540
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const rawUrl = item.json[\"Company Website\"] || \"\";\n  const cleanDomain = rawUrl.replace(/^https?:\\/\\//, \"\").replace(/\\/$/, \"\");\n  const trustpilotUrl = `https://www.trustpilot.com/review/${cleanDomain}`;\n\n  return {\n    json: {\n      \"Trustpilot Website URL\": trustpilotUrl\n    }\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "6116588d-cb2c-4bc4-af6c-1a0b400f9cc4",
      "name": "Remove Duplicate TP URLs",
      "type": "n8n-nodes-base.code",
      "position": [
        2440,
        -3180
      ],
      "parameters": {
        "jsCode": "const seen = new Set();\nconst output = [];\n\nfor (const item of items) {\n  const url = item.json[\"Trustpilot Website URL\"];\n  \n  if (!seen.has(url)) {\n    seen.add(url);\n    output.push({ json: { \"Trustpilot Website URL\": url } });\n  }\n}\n\nreturn output;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c0e0112a-d61a-4241-adaa-08844c77f3bc",
      "name": "Loop Trustpilot URLs",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -420,
        -2740
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "1260b1be-baf0-4d4c-bde2-5a0479704730",
      "name": "Trigger Trustpilot Scraper",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -60,
        -2940
      ],
      "parameters": {
        "url": "https://api.brightdata.com/datasets/v3/trigger",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"input\": [\n    {\n      \"url\": \"{{ $json[\"Trustpilot Website URL\"] }}\",\n      \"date_posted\": \"\"\n    }\n  ],\n  \"custom_output_fields\": [\n    \"company_name\",\n    \"review_id\",\n    \"review_date\",\n    \"review_rating\",\n    \"review_title\",\n    \"review_content\",\n    \"is_verified_review\",\n    \"review_date_of_experience\",\n    \"reviewer_location\",\n    \"reviews_posted_overall\",\n    \"review_replies\",\n    \"review_useful_count\",\n    \"reviewer_name\",\n    \"company_logo\",\n    \"url\",\n    \"company_rating_name\",\n    \"company_overall_rating\",\n    \"is_verified_company\",\n    \"company_total_reviews\",\n    \"5_star\",\n    \"4_star\",\n    \"3_star\",\n    \"2_star\",\n    \"1_star\",\n    \"company_about\",\n    \"company_email\",\n    \"company_phone\",\n    \"company_location\",\n    \"company_country\",\n    \"breadcrumbs\",\n    \"company_category\",\n    \"company_id\",\n    \"company_website\",\n    \"company activity\",\n    \"company_other_categories\",\n    \"review_url\",\n    \"date_posted\"\n  ]\n} ",
        "sendBody": true,
        "sendQuery": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "queryParameters": {
          "parameters": [
            {
              "name": "dataset_id",
              "value": "gd_lm5zmhwd2sni130p"
            },
            {
              "name": "include_errors",
              "value": "true"
            },
            {
              "name": "limit_multiple_results",
              "value": "2"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "7cae1204-b356-42e6-80cb-8333e676cb49",
      "name": "Check Trustpilot Scrape Progress",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        200,
        -2940
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/progress/{{ $json.snapshot_id }}",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d915bb86-bc43-4a7a-afb4-e5264b24e3a1",
      "name": "Verify Trustpilot Scraper Ready",
      "type": "n8n-nodes-base.if",
      "position": [
        400,
        -2940
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "35ed620d-b5d5-4e97-bcc5-52b283d85616",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "ready"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "74fd5339-ef01-4aa2-9646-6ef9e65c9c31",
      "name": "Wait (1 min) Trustpilot Completion",
      "type": "n8n-nodes-base.wait",
      "position": [
        560,
        -2840
      ],
      "parameters": {
        "unit": "minutes",
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "e57b97a7-3904-453c-9fa9-a95e455a77c7",
      "name": "If Trustpilot Has Records",
      "type": "n8n-nodes-base.if",
      "position": [
        940,
        -2820
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f01bd215-c406-493c-a6e4-2b8ec5686b44",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.records }}",
              "rightValue": "={{ 0 }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "40ff595d-c011-4cf8-8353-a97ecf2ecdde",
      "name": "Download Trustpilot Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1180,
        -2840
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/snapshot/{{ $json.snapshot_id }}",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0b535959-7c31-44c9-8d2d-4f3428f4e8dc",
      "name": "Save Trustpilot Data to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1460,
        -2840
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ $json.company_email }}",
            "Rating": "={{ $json.review_rating }}",
            "Address": "={{ $json.company_location }}",
            "Company Name": "={{ $json.company_name }}",
            "Phone Number": "={{ $json.company_phone }}",
            "Company About": "={{ $json.company_about }}"
          },
          "schema": [
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Rating",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Rating",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company About",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Company About",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 972788573,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit#gid=972788573",
          "cachedResultName": "Mail Scrap"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1xkNBckPDGf4YR74bJQN07tAr3qlEoA-70pQc63nBqZ8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit?usp=drivesdk",
          "cachedResultName": "Job Finder sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6,
      "alwaysOutputData": true
    },
    {
      "id": "7e4768b9-0932-4b7c-bdf5-5348cbecb2eb",
      "name": "Read Emails from Trustpilot Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1680,
        -2840
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "=demo@example.com",
              "lookupColumn": "Email"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 972788573,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit#gid=972788573",
          "cachedResultName": "Mail Scrap"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1xkNBckPDGf4YR74bJQN07tAr3qlEoA-70pQc63nBqZ8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/GOOGLE_SHEET_ID_PLACEHOLDER/edit?usp=drivesdk",
          "cachedResultName": "Job Finder sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6,
      "alwaysOutputData": true
    },
    {
      "id": "80e0f93f-5a25-40c5-9413-261781ddca4b",
      "name": "Get Unique Emails",
      "type": "n8n-nodes-base.code",
      "position": [
        1880,
        -2840
      ],
      "parameters": {
        "jsCode": "const seen = new Set();\nconst output = [];\n\nfor (const item of items) {\n  const email = item.json.Email;\n  if (!email || seen.has(email)) continue;\n\n  seen.add(email);\n\n  output.push({\n    json: {\n      email: email\n    }\n  });\n}\n\nreturn output;\n"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "d7301840-e464-4394-ae16-c479a1508bb7",
      "name": "AI Generate Email Content",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2080,
        -2840
      ],
      "parameters": {
        "text": "=`Write a friendly and professional outreach message from a digital marketing agency to the business\n\nThe message should offer services to help them boost their sales and services, such as SEO, ads, and website optimization.\n\nReturn the result in JSON format with:\n{\n  \"email\": \"{{ $json.email }}\"\n}`\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "a1d9596c-c9cd-4111-8b78-8d101020dfa7",
      "name": "Parse Email JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        2480,
        -2840
      ],
      "parameters": {
        "jsCode": "// Fix for parsing AI email output\ntry {\n    const output = $input.first().json.output;\n    \n    // Remove the ```json\\n prefix and ```\\n suffix if present\n    let cleanOutput = output;\n    if (output.startsWith('```json\\n')) {\n        cleanOutput = output.replace(/^```json\\n/, '').replace(/\\n```$/, '');\n    }\n    \n    // Parse the JSON\n    const parsed = JSON.parse(cleanOutput);\n    \n    // Return the email details as separate fields\n    return {\n        email: parsed.email || '',\n        subject: parsed.subject || '',\n        content: parsed.message || parsed.content || ''\n    };\n    \n} catch (error) {\n    // If JSON parsing fails, try to extract info using regex from the raw output\n    const output = $input.first().json.output;\n    \n    const emailMatch = output.match(/\"email\":\\s*\"([^\"]*)\"/);\n    const subjectMatch = output.match(/\"subject\":\\s*\"([^\"]*)\"/);\n    const messageMatch = output.match(/\"message\":\\s*\"([^\"]*(?:\\\\.[^\"]*)*)\"/);\n    \n    return {\n        email: emailMatch ? emailMatch[1] : '',\n        subject: subjectMatch ? subjectMatch[1] : '',\n        content: messageMatch ? messageMatch[1].replace(/\\\\n/g, '\\n').replace(/\\\\\"/g, '\"') : ''\n    };\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "38e46cfe-4fda-4b3d-9921-19a9f73848c1",
      "name": "Send Outreach Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2720,
        -2720
      ],
      "parameters": {
        "sendTo": "={{ $json.email }}",
        "message": "={{ $json.content }}",
        "options": {},
        "subject": "={{ $json.subject }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ae6ec720-694f-43de-be99-fc9baee03622",
      "name": "Gemini - Location AI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -360,
        -3260
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-1.5-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4882a0ef-e8f3-4954-b7bc-5aaaf9566d11",
      "name": "Claude - Email AI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        2020,
        -2680
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-4-20250514",
          "cachedResultName": "Claude 4 Sonnet"
        },
        "options": {}
      },
      "credentials": {
        "anthropicApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e7cfac25-d88e-4504-aaa6-1f74ac04b819",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        -3920
      ],
      "parameters": {
        "color": 4,
        "width": 340,
        "content": "\ud83c\udfaf Smart Location Analysis\n\nAI breaks down cities into sub-locations for comprehensive coverage\n\n\ud83d\udecd Yelp Integration\n\nScrapes business details using BrightData's Yelp dataset\n\n\u2b50 Trustpilot Verification\n\nValidates business credibility through review analysis\n\n\ud83d\udcca Data Storage\n\nAutomatically saves results to Google Sheets\n\n\ud83e\udd16 AI-Powered Outreach\n\nGenerates personalized emails using Claude AI\n\n\ud83d\udce7 Automated Sending\n\nSends emails directly through Gmail integration\n\n\u23f1\ufe0f Estimated Setup Time: 10\u201315 minutes\n\nGoogle Gemini (Location Analysis)\n\nClaude AI (Email Generation)\n\nEdit the \"AI Generate Email Content\" node to customize:\n\n1. BrightData Connection Failed\n\n2. No Data Extracted\n\n3. Gmail Authentication Issues\n\n4. AI Model Errors\n\n\ud83d\udd12 Privacy & Compliance: Ensure GDPR/CCPA compliance. Always respect robots.txt and terms of service of scraped sites.\n\nThis workflow provides a complete solution for automated lead generation and outreach. Customize it to fit your needs and start building your pipeline today!\n\nFor any questions or support, please contact:\n\n\ud83d\udce7 info@incrementors.com\n\nor fill out this form: Contact Us\n\nIncrementors\n\nIncrementors\n\nIncrementors\n\nAkram Kadri\n\nAlex Kim\n\nLucas Perret\n\nJoseph LePage\n\nDr. Firas\n\nDavide\n\nOur customer\u2019s words, not ours.\n\nSkeptical? Try it out, and see for yourself.\n\nBuild complex workflows that other tools can't. I used other tools before. I got to know the N8N and I say it properly: it is better to do everything on the n8n! Congratulations on your work, you are a star!\n\n@igordisco\n\nThank you to the n8n community. I did the beginners course and promptly took an automation WAY beyond my skill level.\n\n@robm\n\nn8n is a beast for automation. self-hosting and low-code make it a dev\u2019s dream. if you\u2019re not automating yet, you\u2019re working too hard.\n\n@Anderoav\n\nI've said it many times. But I'll say it again. n8n is the GOAT. Anything is possible with n8n. You just need some technical knowledge + imagination. I'm actually looking to start a side project. Just to have an excuse to use n8n more \ud83d\ude05\n\n@maximpoulsen\n\nIt blows my mind. I was hating on no-code tools my whole life, but n8n changed everything. Made a Slack agent that can basically do everything, in half an hour.\n\n@felixleber\n\nI just have to say, n8n's integration with third-party services is absolutely mind-blowing. It's like having a Swiss Army knife for automation. So many tasks become a breeze, and I can quickly validate and implement my ideas without any hassle.\n\n@1ronben\n\nFound the holy grail of automation yesterday... Yesterday I tried n8n and it blew my mind \ud83e\udd2f What would've taken me 3 days to code from scratch? Done in 2 hours. The best part? If you still want to get your hands dirty with code (because let's be honest, we developers can't help ourselves \ud83d\ude05), you can just drop in custom code nodes. Zero restrictions.\n\n@francois-la\u00dfl\n\nAnything is possible with n8n. I think @n8n_io Cloud version is great, they are doing amazing stuff and I love that everything is available to look at on Github.\n\n@jodiem\n\nAutomate without limits\n\nImprint\n\n|\n\nSecurity\n\n|\n\nPrivacy\n\n|\n\nReport a vulnerability\n\n\u00a9 2025 n8n \u00a0 | \u00a0 All rights reserved."
      },
      "typeVersion": 1
    },
    {
      "id": "c2c6abba-589f-4e26-a5fc-a563ad3ee3ef",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -4200
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 520,
        "content": "Optimized Workflow Summary:\nThis automation identifies high-quality leads from Yelp and Trustpilot based on a user-submitted location and business category. It uses AI to break down the area into sub-locations, scrapes business details via BrightData, checks credibility through Trustpilot reviews, and stores the best matches in Google Sheets. Finally, AI generates personalized outreach emails, which are automatically sent via Gmail \u2014 enabling fully automated lead generation and email marketing with zero manual effort."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a4b1073a-b560-481c-9208-535aace8da01",
  "connections": {
    "Yelp Scraper": {
      "main": [
        [
          {
            "node": "Check Yelp Scrape Progress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Email JSON": {
      "main": [
        [
          {
            "node": "Send Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Unique Emails": {
      "main": [
        [
          {
            "node": "AI Generate Email Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Yelp Ready": {
      "main": [
        [
          {
            "node": "If Yelp Has Records",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Yelp Scrape Progress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Yelp Results": {
      "main": [
        [
          {
            "node": "Save Yelp Data to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Yelp Has Records": {
      "main": [
        [
          {
            "node": "Fetch Yelp Results",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Loop Yelp Locations": {
      "main": [
        [
          {
            "node": "Clean Unique Websites",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Yelp Scraper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Outreach Email": {
      "main": [
        [
          {
            "node": "Loop Trustpilot URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Sub-locations": {
      "main": [
        [
          {
            "node": "Loop Yelp Locations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Location Analyzer": {
      "main": [
        [
          {
            "node": "Split Sub-locations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Trustpilot URLs": {
      "main": [
        [],
        [
          {
            "node": "Trigger Trustpilot Scraper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make Trustpilot URLs": {
      "main": [
        [
          {
            "node": "Remove Duplicate TP URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Unique Websites": {
      "main": [
        [
          {
            "node": "Read Yelp Sheet Websites",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude - Email AI Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Generate Email Content",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Save Yelp Data to Sheet": {
      "main": [
        [
          {
            "node": "Loop Yelp Locations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Trustpilot Data": {
      "main": [
        [
          {
            "node": "Save Trustpilot Data to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Yelp Sheet Websites": {
      "main": [
        [
          {
            "node": "Make Trustpilot URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicate TP URLs": {
      "main": [
        [
          {
            "node": "Loop Trustpilot URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Generate Email Content": {
      "main": [
        [
          {
            "node": "Parse Email JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Trustpilot Has Records": {
      "main": [
        [
          {
            "node": "Download Trustpilot Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Trustpilot URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Yelp Scrape Progress": {
      "main": [
        [
          {
            "node": "Wait (1 min) Yelp Completion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini - Location AI Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Location Analyzer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Trustpilot Scraper": {
      "main": [
        [
          {
            "node": "Check Trustpilot Scrape Progress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait (1 min) Yelp Completion": {
      "main": [
        [
          {
            "node": "Verify Yelp Ready",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form Trigger - Get User Input": {
      "main": [
        [
          {
            "node": "AI Location Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Trustpilot Data to Sheet": {
      "main": [
        [
          {
            "node": "Read Emails from Trustpilot Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Trustpilot Scraper Ready": {
      "main": [
        [
          {
            "node": "If Trustpilot Has Records",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait (1 min) Trustpilot Completion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Trustpilot Scrape Progress": {
      "main": [
        [
          {
            "node": "Verify Trustpilot Scraper Ready",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Emails from Trustpilot Sheet": {
      "main": [
        [
          {
            "node": "Get Unique Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait (1 min) Trustpilot Completion": {
      "main": [
        [
          {
            "node": "Check Trustpilot Scrape Progress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}