{"record":{"id":"b90d52b6678d1da3","repo":"Zie619/n8n-workflows","slug":"invalid-data-structure","errorCode":null,"errorMessage":"Invalid data structure","messagePattern":"Invalid data structure","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Code/1671_Code_Schedule_Automation_Webhook.json","lineNumber":191,"sourceCode":"      \"parameters\": {\n        \"color\": 4,\n        \"width\": 393.16558441558414,\n        \"height\": 504.17207792207796,\n        \"content\": \"## Save analysis to baserow\\n\\nYou need to create a table in advance to save. \\n- Date (date)\\n- Summary (Long text)\\n- Top pages (Long text)\\n- Blog name (Long text)\"\n      },\n      \"typeVersion\": 1,\n      \"notes\": \"This stickyNote node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"f64cdfbd-712f-461c-b025-25f37e2bded8\",\n      \"name\": \"Parse Umami data\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        940,\n        260\n      ],\n      \"parameters\": {\n        \"jsCode\": \"function transformToUrlString(items) {\\n // In n8n, we need to check if items is an array and get the json property\\n const data = items[0].json;\\n \\n if (!data) {\\n console.log('No valid data found');\\n return encodeURIComponent(JSON.stringify([]));\\n }\\n \\n try {\\n // Create a simplified object with the metrics\\n const simplified = {\\n pageviews: {\\n value: parseInt(data.pageviews.value) || 0,\\n prev: parseInt(data.pageviews.prev) || 0\\n },\\n visitors: {\\n value: parseInt(data.visitors.value) || 0,\\n prev: parseInt(data.visitors.prev) || 0\\n },\\n visits: {\\n value: parseInt(data.visits.value) || 0,\\n prev: parseInt(data.visits.prev) || 0\\n },\\n bounces: {\\n value: parseInt(data.bounces.value) || 0,\\n prev: parseInt(data.bounces.prev) || 0\\n },\\n totaltime: {\\n value: parseInt(data.totaltime.value) || 0,\\n prev: parseInt(data.totaltime.prev) || 0\\n }\\n };\\n \\n return encodeURIComponent(JSON.stringify(simplified));\\n } catch (error) {\\n console.log('Error processing data:', error);\\n throw new Error('Invalid data structure');\\n }\\n}\\n\\n// Get the input data\\nconst items = $input.all();\\n\\n// Process the data\\nconst result = transformToUrlString(items);\\n\\n// Return the result\\nreturn { json: { urlString: result } };\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"470715b6-0878-48b8-b6c6-40de27fbc966\",\n      \"name\": \"Send data to A.I.\",\n      \"type\": \"n8n-nodes-base.httpRequest\",\n      \"position\": [\n        1140,\n        260\n      ],\n      \"parameters\": {\n        \"url\": \"{{ $env.API_BASE_URL }}\",\n        \"method\": \"POST\",\n        \"options\": {},\n        \"jsonBody\": \"={\\n \\\"model\\\": \\\"meta-llama/llama-3.1-70b-instruct:free\\\",\\n \\\"messages\\\": [\\n {\\n \\\"role\\\": \\\"user\\\",\\n \\\"content\\\": \\\"You are an SEO expert. Here is data from Umami analytics of Pennibnotes.com. Where X is URL and Y is number of visitors. Give me a table summary of this data in markdown format:{{ $('Parse Umami data').item.json.urlString }}.\\\"\\n }\\n ]\\n}\",\n        \"sendBody\": true,","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Code/1671_Code_Schedule_Automation_Webhook.json#L173-L209","documentation":"Thrown by the 'Parse Umami data' Code node in a scheduled Umami-analytics workflow. The node's try block builds a simplified metrics object by reading data.pageviews.value, data.visitors.value, etc. If any of those nested objects is undefined, JavaScript raises a TypeError ('Cannot read properties of undefined'), which the catch swallows and rethrows as the generic 'Invalid data structure'.","triggerScenarios":"The Umami stats API response shape changed or returned an error body (auth failure, invalid range, empty result) so items[0].json exists (truthy) but lacks pageviews/visitors/visits/bounces/totaltime sub-objects. Any one missing sub-object triggers the TypeError → catch → this error.","commonSituations":"Umami self-hosted version upgrade changing the /api/websites/:id/stats response; expired or missing auth token making the HTTP node return an error JSON that still lands in json; querying a date range with no data where Umami omits keys; API rate limiting returning a non-metrics body.","solutions":["Inspect the console log line 'Error processing data:' in the execution — it prints the original TypeError telling you exactly which field (e.g. pageviews) is undefined.","Check the upstream HTTP Request node response for the actual Umami payload (auth token valid? correct website id? date range has data?).","Harden the reader with optional chaining and defaults so missing metrics become 0 instead of an exception, if partial data is acceptable.","Pin/verify the Umami API version the workflow was built against after any self-hosted upgrade."],"exampleFix":"// before\nconst simplified = {\n  pageviews: {\n    value: parseInt(data.pageviews.value) || 0,\n    prev: parseInt(data.pageviews.prev) || 0\n  },\n  // ... same for visitors, visits, bounces, totaltime\n};\n\n// after\nconst pick = (obj, k) => ({ value: parseInt(obj?.[k]?.value) || 0, prev: parseInt(obj?.[k]?.prev) || 0 });\nconst simplified = {\n  pageviews: pick(data, 'pageviews'),\n  visitors: pick(data, 'visitors'),\n  visits: pick(data, 'visits'),\n  bounces: pick(data, 'bounces'),\n  totaltime: pick(data, 'totaltime')\n};","handlingStrategy":"type-guard","validationCode":"const data = items[0]?.json;\nconst REQUIRED = ['pageviews', 'visitors', 'visits', 'bounces', 'totaltime'];\nconst complete = data && REQUIRED.every(k => data[k] && 'value' in data[k]);","typeGuard":"function isUmamiStats(d) {\n  return Boolean(d && ['pageviews','visitors','visits','bounces','totaltime']\n    .every(k => d[k] && typeof d[k].value !== 'undefined'));\n}","tryCatchPattern":"try { simplified = buildMetrics(data); } catch (e) { throw new Error(`Umami payload unexpected shape (${e.message}): ${JSON.stringify(data).slice(0, 200)}`); }","preventionTips":["Use optional chaining (data?.pageviews?.value) for every nested read.","Check the upstream HTTP node's status/response before parsing.","Re-throw with the original TypeError message appended — never swallow it into a generic string.","Pin the Umami API version and re-test parsing after upgrades."],"tags":["n8n","umami","analytics","typeerror","code-node"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}