{
  "name": "Monocrawl — Amazon price history to Google Sheets",
  "nodes": [
    {
      "id": "amazon-price-history-to-sheets-manual-test",
      "name": "Manual test",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        -100
      ],
      "parameters": {}
    },
    {
      "id": "amazon-price-history-to-sheets-daily-schedule",
      "name": "Daily schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        100
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 9
            }
          ]
        }
      }
    },
    {
      "id": "amazon-price-history-to-sheets-configure",
      "name": "Configure",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "parameters": {
        "jsCode": "const c = { baseUrl: 'https://www.monocrawl.com', asin: 'REPLACE_ASIN', location: 'United Kingdom', spreadsheetId: 'REPLACE_SPREADSHEET_ID', sheet: 'Prices' };for(const v of Object.values(c))if(String(v).startsWith('REPLACE_'))throw Error('Fill in the settings in this Configure node before running.');return [{json:c}];"
      }
    },
    {
      "id": "amazon-price-history-to-sheets-get-data",
      "name": "Get data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        450,
        0
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ $('Configure').first().json.baseUrl + '/v1/amazon/product' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "asin",
              "value": "={{ $('Configure').first().json.asin }}"
            },
            {
              "name": "location",
              "value": "={{ $('Configure').first().json.location }}"
            }
          ]
        },
        "options": {
          "timeout": 60000,
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      }
    },
    {
      "id": "amazon-price-history-to-sheets-prepare-rows",
      "name": "Prepare rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        0
      ],
      "parameters": {
        "jsCode": "const r=$input.first().json;if(r.success!==true)throw Error(r.error?.message||'Monocrawl request failed');if(r.synthetic||r.degraded||r.stale||r.data?._synthetic)throw Error('The API returned sample or stale fallback data. No destination was updated.');\nconst p=r.data;if(!p?.asin||typeof p.price!=='number'||!Number.isFinite(p.price)||!p.currency)throw Error('A confirmed product price and currency are required; no price row was written.');\nconst state=$getWorkflowStaticData('global'),key=p.asin+':'+p.currency,previous=state.prices?.[key];\nreturn [{json:{observed_at:new Date().toISOString(),asin:p.asin,title:p.title??'',price:p.price,currency:p.currency,price_changed:previous===undefined?'first observation':previous!==p.price,url:p.url??'',request_id:r.request_id??''}}];"
      }
    },
    {
      "id": "amazon-price-history-to-sheets-write-to-google-sheets",
      "name": "Write to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        910,
        0
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "={{ $('Configure').first().json.spreadsheetId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('Configure').first().json.sheet }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "observed_at",
              "displayName": "observed_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "asin",
              "displayName": "asin",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "currency",
              "displayName": "currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price_changed",
              "displayName": "price_changed",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "url",
              "displayName": "url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "request_id",
              "displayName": "request_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {
          "cellFormat": "RAW"
        }
      }
    },
    {
      "id": "amazon-price-history-to-sheets-remember-delivered-data",
      "name": "Remember delivered data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1140,
        0
      ],
      "parameters": {
        "jsCode": "const state=$getWorkflowStaticData('global');state.prices??={};for(const item of $('Prepare rows').all()){const p=item.json;state.prices[p.asin+':'+p.currency]=p.price;}return $input.all();"
      }
    },
    {
      "id": "amazon-price-history-to-sheets-setup-notes",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        260,
        -390
      ],
      "parameters": {
        "width": 680,
        "height": 290,
        "content": "# Amazon price history to Google Sheets\n1. Edit Configure (source, destination and API base URL).\n2. Select a Header Auth credential on Get data: name x-api-key, value your Monocrawl key. Use a key from the same environment as baseUrl.\n3. Connect the Google Sheets credential and create a tab with these headers: observed_at, asin, title, price, currency, price_changed, url, request_id\n4. Run a manual test (charges for one API request; sends/writes real data), then publish to enable the daily schedule.\n\nTracks the displayed product price for one marketplace, not all sellers, coupons or delivery charges. Missing prices fail visibly rather than being recorded as zero.\n\nNo automatic request retry or pagination. See the request log for charges. Keep workflow concurrency at 1 for remembered state."
      }
    }
  ],
  "connections": {
    "Manual test": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily schedule": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure": {
      "main": [
        [
          {
            "node": "Get data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get data": {
      "main": [
        [
          {
            "node": "Prepare rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare rows": {
      "main": [
        [
          {
            "node": "Write to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write to Google Sheets": {
      "main": [
        [
          {
            "node": "Remember delivered data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/London"
  },
  "pinData": {},
  "tags": []
}
