{"record":{"id":"a7a2cbc9efdb846c","repo":"Zie619/n8n-workflows","slug":"invalid-data-structure-a7a2cb","errorCode":null,"errorMessage":"Invalid data structure","messagePattern":"Invalid data structure","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Code/1850_Code_Schedule_Automation_Webhook.json","lineNumber":192,"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":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Code/1850_Code_Schedule_Automation_Webhook.json#L174-L210","documentation":"Identical logic to error 44 but in workflow 1850 (a copy of the Umami analytics workflow). The 'Parse Umami data' node dereferences data.pageviews.value etc. inside a try block; a missing sub-object throws a TypeError that the catch converts to 'Invalid data structure'. The message unfortunately hides the original error.","triggerScenarios":"The Umami stats endpoint response lacks any of pageviews/visitors/visits/bounces/totaltime (auth error body, version-drift payload, empty date range), making one of the chained .value reads throw.","commonSituations":"Umami token expired so the HTTP node emitted an error JSON; Umami upgraded with a changed stats schema; website id misconfigured; scheduled run hitting a range with no data.","solutions":["Open the execution log and read the 'Error processing data:' line to see the real TypeError and which field is missing.","Validate the upstream Umami response (status 200, contains the five metric keys) before parsing.","Rewrite the reads with optional chaining so absent metrics default to 0 instead of throwing.","Keep this workflow copy in sync with fixes made to its sibling (1671) — they share the bug."],"exampleFix":"// before\nconst simplified = {\n  pageviews: { value: parseInt(data.pageviews.value) || 0, prev: parseInt(data.pageviews.prev) || 0 },\n  // ...\n};\n\n// after\nconst metric = (k) => ({ value: parseInt(data?.[k]?.value) || 0, prev: parseInt(data?.[k]?.prev) || 0 });\nconst simplified = ['pageviews','visitors','visits','bounces','totaltime'].reduce((acc, k) => (acc[k] = metric(k), acc), {});","handlingStrategy":"type-guard","validationCode":"const data = items[0]?.json;\nconst ok = data && ['pageviews','visitors','visits','bounces','totaltime'].every(k => data[k] && 'value' in data[k]);","typeGuard":"function isUmamiStats(d) {\n  return Boolean(d && ['pageviews','visitors','visits','bounces','totaltime'].every(k => d?.[k]?.value !== undefined));\n}","tryCatchPattern":"catch (error) { throw new Error(`Invalid Umami data structure: ${error.message}`); } // preserve the cause","preventionTips":["Optional-chain every nested metric read.","Verify the Umami token/site id before the parse node runs.","Preserve original error text when re-throwing from a catch.","Fix sibling copies of this workflow (1671/1850) together."],"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"}