{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "588abc91-e839-4f69-b5b1-dcd33b6bcd48",
      "name": "When clicking \u2018Test workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -460,
        -80
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2481cb1d-6309-4e32-970c-3b68c556758f",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -180,
        -80
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Jf8qNEg-KTh__aZ8L5YS5iMmBZLEEKCYipIszWARCmw/edit#gid=0",
          "cachedResultName": "input"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Jf8qNEg-KTh__aZ8L5YS5iMmBZLEEKCYipIszWARCmw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Jf8qNEg-KTh__aZ8L5YS5iMmBZLEEKCYipIszWARCmw/edit?usp=drivesdk",
          "cachedResultName": "Items"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "e165f017-7abf-4a5c-82d4-97013b25b582",
      "name": "Wait 30s - Polling Bright Data",
      "type": "n8n-nodes-base.wait",
      "position": [
        480,
        -440
      ],
      "parameters": {
        "amount": 30
      },
      "executeOnce": false,
      "typeVersion": 1.1
    },
    {
      "id": "8cbd727d-9104-4d40-8ec2-0a4718c0e4e0",
      "name": "Snapshot Progress",
      "type": "n8n-nodes-brightdata.brightData",
      "position": [
        700,
        -440
      ],
      "parameters": {
        "resource": "marketplaceDataset",
        "operation": "getSnapshotMetadata",
        "snapshot_id": "={{ $json.snapshot_id }}"
      },
      "credentials": {
        "brightdataApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0ce012a2-6827-4128-9642-c22f97f5a89d",
      "name": "Snapshot Content",
      "type": "n8n-nodes-brightdata.brightData",
      "position": [
        360,
        40
      ],
      "parameters": {
        "resource": "marketplaceDataset",
        "operation": "getSnapshotContent",
        "snapshot_id": "={{ $('Snapshot Request').item.json.snapshot_id }}"
      },
      "credentials": {
        "brightdataApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3b4c2dc2-9191-411d-b9eb-1c9038b3e82c",
      "name": "Snapshot Request",
      "type": "n8n-nodes-brightdata.brightData",
      "position": [
        260,
        -440
      ],
      "parameters": {
        "resource": "marketplaceDataset",
        "operation": "filterDataset",
        "dataset_id": {
          "__rl": true,
          "mode": "list",
          "value": "gd_ltppk50q18kdw67omz",
          "cachedResultName": "Google Shopping"
        },
        "filter_type": "filters_group",
        "filters_group": "={\"operator\":\"and\",\"filters\":[{\"name\":\"title\",\"operator\":\"includes\",\"value\":\"{{$json.title}}\"},\n{\"name\":\"item_price\",\"operator\":\"is_not_null\"}]}"
      },
      "credentials": {
        "brightdataApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1421cc56-469e-4a7a-8a73-c3f8aff795c1",
      "name": "If - Checking status of Snapshot",
      "type": "n8n-nodes-base.if",
      "position": [
        920,
        -440
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7932282b-71bb-4bbb-ab73-4978e554de7e",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "running"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f774e258-3da9-4ad9-8843-04814ac64ec0",
      "name": "Check if snapshot ready",
      "type": "n8n-nodes-base.if",
      "position": [
        800,
        40
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "645d85d3-c5cc-4e51-a989-075c0a851449",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{ $json.isArray}}",
              "rightValue": "false"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e434c805-06f3-4497-b21c-897ff7aab9d4",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        100,
        -80
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "30e1f4f1-9cee-493f-9b52-0998ebd2c2da",
      "name": "If - Checking status for errors",
      "type": "n8n-nodes-base.if",
      "position": [
        1140,
        -380
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7932282b-71bb-4bbb-ab73-4978e554de7e",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "failed"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ff36ddb4-c22a-4bf7-9776-a12ffbad0280",
      "name": "Code - Check If Snapshot is built",
      "type": "n8n-nodes-base.code",
      "position": [
        580,
        40
      ],
      "parameters": {
        "jsCode": "const value = $json.items;\nconst isArray = Array.isArray(value);\n\nreturn [\n  {\n    json: {\n      isArray: isArray,\n      original: value\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "036893c2-57f7-4e69-a617-9c8f256d33cf",
      "name": "Code - Extract Necessary Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1020,
        40
      ],
      "parameters": {
        "jsCode": "const input = items[0].json.original;\nconst posts = Array.isArray(input) ? input : [];\n\n// \u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0442\u0435, \u0433\u0434\u0435 item_price \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442\nconst filteredPosts = posts.filter(post =>\n  post && post.item_price !== null && post.item_price !== undefined\n);\n\n// \u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f\nconst extracted = filteredPosts.map(post => {\n  return {\n    price: post.item_price,\n    seller_name: post.seller_name || null,\n    title: post.title || null,\n    url: post.url || null,\n  };\n});\n\nreturn [\n  {\n    json: {\n      items: extracted\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "dfa86828-7bcf-423f-ad24-8b1a39d92d50",
      "name": "Email Report",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        2020,
        240
      ],
      "parameters": {
        "html": "={{ $json.html }}",
        "options": {},
        "subject": "=Your N8N report about {{ $('Loop Over Items').item.json.title }}",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "1194906b-74d1-4cee-9429-7d9168ee97a5",
      "name": "Error message (replace with webhook/other notifier if needed)",
      "type": "n8n-nodes-base.set",
      "position": [
        1380,
        -300
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c1137a35-0854-4af2-b22d-6d7817f2a2f2",
              "name": "message",
              "type": "string",
              "value": "=Bright Data snapshot error for item \"{{ $('Loop Over Items').item.json.title }}\": \n{{ $('Snapshot Progress').item.json.warning }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a9f8c6fb-b8c4-45bf-a452-20544dd2b72f",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1260,
        260
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9f3f912d-9d9a-4269-86a2-e6edbe26c793",
      "name": "Compare Prices and Generate Report",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1240,
        40
      ],
      "parameters": {
        "text": "={{$json}}",
        "messages": {
          "messageValues": [
            {
              "message": "=Analyze these listings from Google Shopping and identify the top 20 sources (stores or websites) offering the lowest prices. Provide a ranked list including the seller name, product price, and link to the listing if available. Ensure all product names match or are highly relevent to {{ $('Loop Over Items').item }}. Don't start your answer with 'Okay'. Return all the text as Markdown."
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.6
    },
    {
      "id": "8b564b07-5f07-4d45-b3c2-203e56d23617",
      "name": "Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        1620,
        40
      ],
      "parameters": {
        "mode": "markdownToHtml",
        "options": {},
        "markdown": "={{ $json.text }}",
        "destinationKey": "html"
      },
      "typeVersion": 1
    },
    {
      "id": "67e40e23-e514-435f-8795-81e8112b2234",
      "name": "Code - Build HTML",
      "type": "n8n-nodes-base.code",
      "position": [
        1840,
        40
      ],
      "parameters": {
        "jsCode": "const rawHtml = $json.html;\n\nreturn [{\n  json: {\n    html: `\n      <html>\n        <head>\n          <style>\n            body { font-family: Arial, sans-serif; line-height: 1.5; font-size: 15px; }\n            h1, h2, h3 { color: #333; }\n            a { color: #1a73e8; text-decoration: none; }\n            ul { padding-left: 20px; }\n            li { margin-bottom: 6px; }\n          </style>\n        </head>\n        <body>\n          ${rawHtml}\n        </body>\n      </html>\n    `\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "613822ea-6e5c-4aba-a4c5-84a1a696a446",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        80
      ],
      "parameters": {
        "height": 240,
        "content": "\u26a0\ufe0f Note\nItem searching in the dataset is case-sensitive.\n\nMake sure that the item names in your table are typed correctly.\nFor example:\nUse \"Iphone\" instead of \"iphone\", \"GeForce\" instead of \"Geforce\", and so on.\n\nOtherwise, your search may return zero results."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Markdown": {
      "main": [
        [
          {
            "node": "Code - Build HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Report": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Snapshot Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Snapshot Content": {
      "main": [
        [
          {
            "node": "Code - Check If Snapshot is built",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Snapshot Request": {
      "main": [
        [
          {
            "node": "Wait 30s - Polling Bright Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Build HTML": {
      "main": [
        [
          {
            "node": "Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Snapshot Progress": {
      "main": [
        [
          {
            "node": "If - Checking status of Snapshot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if snapshot ready": {
      "main": [
        [
          {
            "node": "Snapshot Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code - Extract Necessary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Compare Prices and Generate Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Code - Extract Necessary Data": {
      "main": [
        [
          {
            "node": "Compare Prices and Generate Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 30s - Polling Bright Data": {
      "main": [
        [
          {
            "node": "Snapshot Progress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If - Checking status for errors": {
      "main": [
        [
          {
            "node": "Error message (replace with webhook/other notifier if needed)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Snapshot Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If - Checking status of Snapshot": {
      "main": [
        [
          {
            "node": "If - Checking status for errors",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 30s - Polling Bright Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Check If Snapshot is built": {
      "main": [
        [
          {
            "node": "Check if snapshot ready",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Test workflow\u2019": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare Prices and Generate Report": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error message (replace with webhook/other notifier if needed)": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}