{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "0e56a2f3-4977-498b-9434-e10b717779b9",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        160,
        -1400
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "88ac7caa-6408-4b4b-96ef-b5b575da9d52",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -800,
        -840
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "170b1458-07a1-4295-af4b-c87022eef71c",
      "name": "Check Status by Snapshot ID",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        380,
        -1400
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/progress/{{ $json.snapshot_id }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9c020893-da19-48b1-8816-594bed76ae16",
      "name": "Get the data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1180,
        -1400
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/snapshot/{{ $json.snapshot_id }}",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "02f3e1e6-55af-4472-999b-9a656ba8c76f",
      "name": "Initiate request from URLs",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        440,
        -700
      ],
      "parameters": {
        "url": "https://api.brightdata.com/datasets/v3/trigger",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ $json.data.map(i => {\nreturn {url:i['Product URL'],\nzipcode: i['ZIP code']\n}\n}).toJsonString() }}",
        "sendBody": true,
        "sendQuery": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "dataset_id",
              "value": "gd_l7q7dkf244hwjntr0"
            },
            {
              "name": "include_errors",
              "value": "true"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "credentials": {
        "brightdataApi": {
          "name": "<your credential>"
        },
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ecf9d3e8-5435-4426-a82b-b5dd6ff85e86",
      "name": "Read data from Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -420,
        -840
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-cX3l_oxylIH2J8rzC-LN0XmFoOOXjJGW0bUe-4bsAw/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1-cX3l_oxylIH2J8rzC-LN0XmFoOOXjJGW0bUe-4bsAw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-cX3l_oxylIH2J8rzC-LN0XmFoOOXjJGW0bUe-4bsAw/edit?usp=drivesdk",
          "cachedResultName": "Sample Amazon Products Monitoring"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "c079c769-406e-43d0-9f41-11db53da340f",
      "name": "Process URLs by batch of 10s",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        20,
        -720
      ],
      "parameters": {
        "options": {},
        "batchSize": 10
      },
      "typeVersion": 3
    },
    {
      "id": "89930387-958b-48c3-8583-8f2aac59718b",
      "name": "Combine the batch",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        240,
        -720
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "8ad0c86a-5107-4ccc-b2d6-e4dda7c98b4f",
      "name": "Update the records by ASIN",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1520,
        -1400
      ],
      "parameters": {
        "columns": {
          "value": {
            "ASIN": "={{ $json.asin }}",
            "Price": "={{ $json.final_price }}"
          },
          "schema": [
            {
              "id": "Product URL",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Product URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Price",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Product Title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Product Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ZIP code",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "ZIP code",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ASIN",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ASIN",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "ASIN"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-cX3l_oxylIH2J8rzC-LN0XmFoOOXjJGW0bUe-4bsAw/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1-cX3l_oxylIH2J8rzC-LN0XmFoOOXjJGW0bUe-4bsAw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-cX3l_oxylIH2J8rzC-LN0XmFoOOXjJGW0bUe-4bsAw/edit?usp=drivesdk",
          "cachedResultName": "Sample Amazon Products Monitoring"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "636aa558-8973-4493-8788-f566edf5021b",
      "name": "Check the status of snapshot",
      "type": "n8n-nodes-base.switch",
      "position": [
        620,
        -1400
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a2198ad8-e1ae-411d-8c6b-38e74b727560",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "ready"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b8fa19aa-f90c-4da5-a039-9962f2a34776",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "running"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "920f766f-2815-46c9-bd24-30d6f4490c58",
      "name": "Space the request by 1 second",
      "type": "n8n-nodes-base.wait",
      "position": [
        660,
        -660
      ],
      "parameters": {
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "1d79897c-2139-4579-b86e-d9b0bea9e0bc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -840,
        -1080
      ],
      "parameters": {
        "color": 4,
        "width": 700,
        "height": 460,
        "content": "## Schedule and Read from Google Sheets\nSet up or modify a Google Sheet. The sheet should have columns named \u201cProduct URL,\u201d \u201cZIP code,\u201d and \u201cASIN.\u201d The \u201cASIN\u201d column should be a function that extracts the ASIN from the product URL. The formula to achieve this is:\n```\n=REGEXEXTRACT(A4, \u201c/(?:dp|gp/product|product)/([A-Z0-9]{10})\u201d)"
      },
      "typeVersion": 1
    },
    {
      "id": "9e8866c2-8ae1-467f-a6fb-ce0d1a9e1ac5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        -860
      ],
      "parameters": {
        "color": 5,
        "width": 940,
        "height": 460,
        "content": "## Process Data into Bright Data by batch\n\n Obtain an API key from Bright Data and create a generic bearer authentication credential."
      },
      "typeVersion": 1
    },
    {
      "id": "b894627b-e326-40a8-8656-db4e1c18a8d2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -1540
      ],
      "parameters": {
        "width": 740,
        "height": 460,
        "content": "## Check the requested data from Bright Data using snapshot ID\n\nThis checks if the snapshot has processed the data. If the data is ready, it proceeds to the \u2018true\u2019 branch of the If node."
      },
      "typeVersion": 1
    },
    {
      "id": "5439d333-922f-4a6f-a391-6963f57be0be",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1060,
        -1540
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 460,
        "content": "## Obtain the data from the snapshot and update it to Google Sheets"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Check Status by Snapshot ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get the data": {
      "main": [
        [
          {
            "node": "Update the records by ASIN",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Read data from Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine the batch": {
      "main": [
        [
          {
            "node": "Initiate request from URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Initiate request from URLs": {
      "main": [
        [
          {
            "node": "Space the request by 1 second",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Status by Snapshot ID": {
      "main": [
        [
          {
            "node": "Check the status of snapshot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read data from Google Sheet": {
      "main": [
        [
          {
            "node": "Process URLs by batch of 10s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check the status of snapshot": {
      "main": [
        [
          {
            "node": "Get the data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process URLs by batch of 10s": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Combine the batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Space the request by 1 second": {
      "main": [
        [
          {
            "node": "Process URLs by batch of 10s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}