Zie619/n8n-workflows · error · Error
Invalid EDI data format. Please ensure the input is from the
Error message
Invalid EDI data format. Please ensure the input is from the EDI parser.
What it means
Thrown by 'Flatten Data to Orderlines' (workflow 0793). It reads parsedEDI = $input.all()[0].json and requires parsedEDI.orderDetails to exist — the signature object produced by the 'Parse EDI Message' node (which always sets orderDetails, even if empty). This error therefore means the input is not a Parse-EDI output: a different node's item arrived.
Source
Thrown at workflows/Splitout/0793_Splitout_Code_Send_Triggered.json:1377
-4040,
-880
],
"parameters": {
"mode": "combineBySql"
},
"typeVersion": 3,
"notes": "This merge node performs automated tasks as part of the workflow."
},
{
"id": "e64a1db7-4c22-4925-9597-9c14fdddbfe4",
"name": "Flatten Data to Orderlines",
"type": "n8n-nodes-base.code",
"position": [
-4460,
-860
],
"parameters": {
"jsCode": "// EDI to Flattened Tabular Data Transformer for n8n JavaScript node\nfunction transformToFlattened(parsedEDI) {\n const flattened = [];\n \n // Create a header object with all order header fields\n const headerObj = {\n header_Document_Type: parsedEDI.orderDetails.documentType || '',\n header_Document_Number: parsedEDI.orderDetails.documentNumber || '',\n header_Message_Function: parsedEDI.orderDetails.messageFunction || '',\n header_Sender_ID: parsedEDI.interchangeHeader.senderId || '',\n header_Receiver_ID: parsedEDI.interchangeHeader.receiverId || '',\n header_Date: parsedEDI.interchangeHeader.dateTime || '',\n header_Time: parsedEDI.interchangeHeader.time || '',\n header_Control_Reference: parsedEDI.interchangeHeader.controlReference || ''\n };\n \n // Process all dates\n const dateObjs = {};\n if (parsedEDI.dates && Array.isArray(parsedEDI.dates)) {\n parsedEDI.dates.forEach((date, index) => {\n const prefix = `date${index + 1}_`;\n dateObjs[`${prefix}Qualifier`] = date.qualifier || '';\n dateObjs[`${prefix}Description`] = date.description || '';\n dateObjs[`${prefix}Date`] = date.date || '';\n dateObjs[`${prefix}Format`] = date.format || '';\n });\n }\n \n // Process all parties\n const partyObjs = {};\n if (parsedEDI.parties && Array.isArray(parsedEDI.parties)) {\n parsedEDI.parties.forEach((party, index) => {\n const prefix = `party${index + 1}_`;\n partyObjs[`${prefix}Type`] = party.partyQualifier || '';\n partyObjs[`${prefix}Description`] = party.qualifierDescription || '';\n partyObjs[`${prefix}ID`] = party.partyId || '';\n partyObjs[`${prefix}Name`] = party.partyName || '';\n });\n }\n \n // Create one row for each line item with all header, date, and party info\n if (parsedEDI.lineItems && Array.isArray(parsedEDI.lineItems)) {\n parsedEDI.lineItems.forEach((item) => {\n const lineItem = {\n line_Number: item.lineNumber || '',\n line_Product_ID: item.productId || '',\n line_Product_ID_Type: item.productIdType || '',\n line_Description: item.description || '',\n line_Quantity: item.quantity || 0,\n line_Unit: item.unit || '',\n line_Price: item.price || 0,\n line_Price_Qualifier: item.priceQualifier || ''\n };\n \n // Combine all information into one flat object\n const flatRow = {\n ...headerObj,\n ...dateObjs,\n ...partyObjs,\n ...lineItem\n };\n \n flattened.push(flatRow);\n });\n }\n \n // If there are no line items, create at least one row with header info\n if (flattened.length === 0) {\n flattened.push({\n ...headerObj,\n ...dateObjs,\n ...partyObjs\n });\n }\n \n return flattened;\n}\n\nconst parsedEDI = $input.all()[0].json;\n\n// Make sure we have valid data\nif (!parsedEDI || !parsedEDI.orderDetails) {\n throw new Error('Invalid EDI data format. Please ensure the input is from the EDI parser.');\n}\n\nconst flattenedData = transformToFlattened(parsedEDI);\n\n// Return the flattened data\nreturn { json: { data: flattenedData } };"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},
{
"id": "5b56fe40-9cfb-4668-946d-470dc9e3a39e",
"name": "Split Out by Line",
"type": "n8n-nodes-base.splitOut",
"position": [
-4280,
-860
],
"parameters": {
"options": {},
"fieldToSplitOut": "data"
},
"typeVersion": 1,
"notes": "This splitOut node performs automated tasks as part of the workflow."View on GitHub (pinned to 94007c1445)
Solutions
- Verify the connection: 'Flatten Data to Orderlines' input must come from 'Parse EDI Message' output.
- If a Merge node sits in the path, ensure the parser branch is index 0 or address its output by name (see exampleFix).
- Validate the full parsed shape (orderDetails AND lineItems) rather than one field.
- Pin the parser output and run the flatten node alone to confirm the mapping.
Example fix
// before
const parsedEDI = $input.all()[0].json;
if (!parsedEDI || !parsedEDI.orderDetails) {
throw new Error('Invalid EDI data format. Please ensure the input is from the EDI parser.');
}
// after
const parsedEDI = $('Parse EDI Message').first().json;
if (!parsedEDI || typeof parsedEDI !== 'object' || !('orderDetails' in parsedEDI)) {
throw new Error(`Invalid EDI data format (got keys: ${parsedEDI ? Object.keys(parsedEDI).join(',') : 'null'})`);
} Defensive patterns
Strategy: type-guard
Validate before calling
const parsedEDI = $('Parse EDI Message').first().json;
if (!parsedEDI || !('orderDetails' in parsedEDI) || !Array.isArray(parsedEDI.lineItems)) {
throw new Error('Input is not Parse EDI Message output');
} Type guard
function isParsedEdi(json) {
return !!json && typeof json === 'object'
&& 'orderDetails' in json && Array.isArray(json.lineItems) && 'summary' in json;
} Prevention
- Reference upstream nodes by name ($('Parse EDI Message')) instead of positional $input.all()[0] when a Merge sits in the path.
- Validate the full parser signature (orderDetails + lineItems + summary), not one field.
- Re-verify canvas wiring after inserting Merge nodes.
When it happens
Trigger: Wiring puts the wrong item first: the Merge node visible before this node in the file outputs combined items whose json is the raw EDI string or something else without orderDetails; or the connection order was changed so Flatten runs before/parallel to the parser; or the parse node was skipped by a branch condition.
Common situations: Editing the canvas and reconnecting the Flatten node to the Merge/trigger instead of the parser; a Merge (append) mode putting a non-parsed item at index 0; someone deleted or bypassed 'Parse EDI Message' while testing.
Related errors
- No category in Code2
- No EDI message found in input. Please provide the EDI messag
- Initial Vector 'data' is undefined or missing.
- Initial Vector 'data' is in an unsupported format.
- AES Key is missing.
AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15).
Data as JSON: /api/errors/e066ef86af974af0.
Report an issue: GitHub.