{"record":{"id":"970d104488e37d61","repo":"Zie619/n8n-workflows","slug":"invalid-input-data-format","errorCode":null,"errorMessage":"Invalid input data format","messagePattern":"Invalid input data format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Wait/1954_Wait_Code_Automation_Webhook.json","lineNumber":153,"sourceCode":"      \"parameters\": {\n        \"url\": \"{{ $env.BASE_URL }}\",\n        \"options\": {}\n      },\n      \"retryOnFail\": true,\n      \"typeVersion\": 4.2,\n      \"waitBetweenTries\": 5000,\n      \"notes\": \"This httpRequest node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"c4f38893-636a-4293-9e10-395be30683d0\",\n      \"name\": \"Parse Data\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        500,\n        -200\n      ],\n      \"parameters\": {\n        \"jsCode\": \"// Ensure input data exists\\nif (!$json || !$json.data) {\\n    throw new Error(\\\"Invalid input data format\\\");\\n}\\n\\n// Parse the JSON string inside `data`\\nlet parsedData;\\ntry {\\n    parsedData = JSON.parse($json.data);\\n} catch (error) {\\n    throw new Error(\\\"Error parsing JSON data: \\\" + error.message);\\n}\\n\\n// Extract available and unavailable domains safely\\nconst availableDomains = parsedData.reply?.available ? Object.values(parsedData.reply.available) : [];\\nconst unavailableDomains = parsedData.reply?.unavailable ? Object.values(parsedData.reply.unavailable) : [];\\n\\n// Prepare the output array\\nconst output = [];\\n\\n// Process available domains\\navailableDomains.forEach(domainObj => {\\n    if (domainObj && domainObj.domain) {\\n        output.push({\\n            Domain: domainObj.domain,\\n            Availability: \\\"Available\\\"\\n        });\\n    }\\n});\\n\\n// Process unavailable domains\\nunavailableDomains.forEach(domain => {\\n    if (typeof domain === \\\"string\\\") {\\n        output.push({\\n            Domain: domain,\\n            Availability: \\\"Unavailable\\\"\\n        });\\n    } else if (typeof domain === \\\"object\\\" && domain.domain) {\\n        output.push({\\n            Domain: domain.domain,\\n            Availability: \\\"Unavailable\\\"\\n        });\\n    }\\n});\\n\\n// Return the structured data\\nreturn output;\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"ec7b8311-65b7-45b0-85ae-b91d7c82e123\",\n      \"name\": \"Convert to Excel\",\n      \"type\": \"n8n-nodes-base.convertToFile\",\n      \"position\": [\n        500,\n        0\n      ],\n      \"parameters\": {\n        \"options\": {\n          \"fileName\": \"domain_results.xlsx\"\n        },\n        \"operation\": \"xlsx\",\n        \"binaryPropertyName\": \"={{ $json.MergedDomains }}\"","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Wait/1954_Wait_Code_Automation_Webhook.json#L135-L171","documentation":"Thrown by the 'Parse Data' Code node when $json.data is absent, i.e. the item coming from the previous HTTP request node does not carry the expected data field containing a JSON string. The node JSON.parses $json.data and splits parsedData.reply.available / .unavailable into Domain/Availability rows for Excel export. Any upstream response that changes shape (error body, envelope change, empty reply) breaks the guard.","triggerScenarios":"The domain-availability API returned an error envelope (e.g., {error: 'rate limited'}) with no .data, the response was already parsed to an object so $json.data is an object (guard passes but JSON.parse throws the sibling error), a proxy/queue step renamed the field, or the HTTP node returned the raw body under a different property.","commonSituations":"API outage or auth expiry returning HTML/JSON error instead of the normal payload, response-format option on the HTTP Request node changed (String vs JSON), or upstream API version bump re-wrapping the reply.","solutions":["Execute the HTTP node standalone and inspect its output keys to see what the API actually returned (often an error message explains it).","If $json.data can be an object, handle both: typeof d === 'string' ? JSON.parse(d) : d.","Add an IF node on the HTTP response status/code so error payloads route to an error branch before parsing.","Fix auth/rate-limit on the upstream API if error envelopes are the cause."],"exampleFix":"// before\nif (!$json || !$json.data) {\n    throw new Error(\"Invalid input data format\");\n}\nlet parsedData;\ntry {\n    parsedData = JSON.parse($json.data);\n} catch (error) {\n    throw new Error(\"Error parsing JSON data: \" + error.message);\n}\n\n// after - accept object or string, report the real shape\nif (!$json || (!$json.data && !$json.reply)) {\n    throw new Error(`Invalid input data format. Item keys: ${$json ? Object.keys($json).join(', ') : 'null'}`);\n}\nconst raw = $json.data ?? $json;\nconst parsedData = typeof raw === 'string' ? JSON.parse(raw) : raw;","handlingStrategy":"try-catch","validationCode":"if (!$json || (!$json.data && !$json.reply)) {\n  throw new Error(`Invalid input data format. Keys: ${$json ? Object.keys($json).join(', ') : 'null'}`);\n}\nconst raw = $json.data ?? $json;\nconst parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;\nif (!parsed?.reply) {\n  throw new Error(`Unexpected API envelope: ${JSON.stringify(parsed).slice(0, 200)}`);\n}","typeGuard":"const hasDomainReply = (p) => p != null && p.reply != null &&\n  (p.reply.available != null || p.reply.unavailable != null);","tryCatchPattern":"try {\n  const parsed = typeof $json.data === 'string' ? JSON.parse($json.data) : $json.data;\n  if (!parsed?.reply) throw new Error('API envelope missing .reply');\n  return toRows(parsed);\n} catch (e) {\n  throw new Error(`Parse Data failed: ${e.message}; body preview: ${JSON.stringify($json).slice(0, 200)}`);\n}","preventionTips":["Check the HTTP node's response format option (String vs JSON) — it determines whether $json.data is a string to parse or already an object.","Route non-2xx responses to an error branch (IF on status) before parsing nodes.","Snapshot a real API response as pinned data to lock the envelope shape."],"tags":["n8n","code-node","validation","http-request","json-parsing","domain-api"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}