{
  "name": "CrawlerData: daily Google Shopping prices to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 7
            }
          ]
        }
      },
      "id": "b1f0d2a4-0001-4c1e-9a10-000000000001",
      "name": "Every day at 07:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {},
      "id": "b1f0d2a4-0006-4c1e-9a10-000000000006",
      "name": "Test run",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        200
      ]
    },
    {
      "parameters": {
        "jsCode": "// One item per product search to check. Edit this list.\nreturn [\n  { json: { query: 'sony wh-1000xm5', country: 'us' } },\n  { json: { query: 'apple airpods pro 2', country: 'us' } },\n];"
      },
      "id": "b1f0d2a4-0002-4c1e-9a10-000000000002",
      "name": "Products to check",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.crawlerdata.com/v1/jobs",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ endpoint: 'google-shopping-search', params: { query: $json.query, country: $json.country }, queue: 'live' }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 1000
            }
          },
          "timeout": 200000
        }
      },
      "id": "b1f0d2a4-0003-4c1e-9a10-000000000003",
      "name": "CrawlerData: Google Shopping search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "CrawlerData API key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Top 5 offers per search, one row each.\nconst day = new Date().toISOString().slice(0, 10);\nconst rows = [];\nfor (const item of $input.all()) {\n  const { job, result } = item.json;\n  if (job.status !== 'completed') continue; // failed jobs cost 0 credits\n  for (const p of result.shopping_results.slice(0, 5)) {\n    rows.push({ json: {\n      date: day,\n      query: result.search_parameters.query,\n      position: p.position,\n      title: p.title,\n      merchant: p.merchant,\n      price: p.price ? p.price.value : null,\n      currency: p.price ? p.price.currency : null,\n      product_id: p.product_id,\n    } });\n  }\n}\nreturn rows;"
      },
      "id": "b1f0d2a4-0004-4c1e-9a10-000000000004",
      "name": "Flatten to rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Prices"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "b1f0d2a4-0005-4c1e-9a10-000000000005",
      "name": "Append to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        880,
        0
      ]
    }
  ],
  "connections": {
    "Every day at 07:00": {
      "main": [
        [
          {
            "node": "Products to check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Products to check": {
      "main": [
        [
          {
            "node": "CrawlerData: Google Shopping search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CrawlerData: Google Shopping search": {
      "main": [
        [
          {
            "node": "Flatten to rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flatten to rows": {
      "main": [
        [
          {
            "node": "Append to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Test run": {
      "main": [
        [
          {
            "node": "Products to check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
