Zie619/n8n-workflows · error · Error
Invalid quantity: ${input["Quantity Received"]}
Error message
Invalid quantity: ${input["Quantity Received"]} What it means
Thrown by 'Calculate Total Price' when the webhook field `Quantity Received` cannot be parsed to a number. The getNumber helper strips non-numeric characters, runs parseFloat, and returns null for undefined/null/empty/NaN - the throw then reports the raw value.
Source
Thrown at workflows/Code/0926_Code_Webhook_Create_Webhook.json:800
"mode": "list",
"value": "1q0S6AVK7uxZG8sUQkpcZr01KToHPjOZ0gG3zKHLR6lw",
"cachedResultUrl": "{{ $env.WEBHOOK_URL }}",
"cachedResultName": "Plumbee Raw Material Delivery (Responses)"
}
},
"typeVersion": 4.5,
"notes": "This googleSheets node performs automated tasks as part of the workflow."
},
{
"id": "21c17077-9f9a-489a-b6a5-ea7a70a85cee",
"name": "Calculate Total Price",
"type": "n8n-nodes-base.code",
"position": [
6340,
2040
],
"parameters": {
"jsCode": "// Get the input data\nconst input = $input.all()[0].json;\n\n// Debug: Log the entire input to see all available fields\nconsole.log(\"Complete Input Data:\", JSON.stringify(input, null, 2));\n\n// Improved number parser that handles different formats\nconst getNumber = (value) => {\n if (value === undefined || value === null || value === \"\") return null;\n \n // Remove any currency symbols, commas, or extra spaces\n const cleaned = String(value)\n .replace(/[^\\d.-]/g, '')\n .trim();\n \n const num = parseFloat(cleaned);\n return isNaN(num) ? null : num;\n};\n\n// Use EXACT field names from your webhook payload\nconst quantity = getNumber(input[\"Quantity Received\"]); // Not \"Quantity Received\"\nconst unitPrice = getNumber(input[\"Unit Price\"]); // Not \"Unit Price\"\n\n// Validate\nif (quantity === null) throw new Error(`Invalid quantity: ${input[\"Quantity Received\"]}`);\nif (unitPrice === null) throw new Error(`Invalid price: ${input[\"Unit Price\"]}`);\n\n// Calculate total\nconst totalPrice = quantity * unitPrice;\n\n// Return results\n// Return clean output without debug info\nreturn {\n json: {\n \"Timestamp\": new Date().toISOString(),\n \"Product ID\": input[\"Product ID\"],\n \"Supplier Name\": input[\"Supplier Name\"],\n \"Material Name\": input[\"Material Name\"],\n \"Quantity Received\": quantity,\n \"Description\": input[\"Description\"] || \"\",\n \"Measurement Unit\": input[\"Measurement Unit\"],\n \"Unit Price\": unitPrice,\n \"Total Price\": totalPrice.toFixed(2),\n \"Date of Delivery\": input[\"Date of Delivery\"],\n \"Received By\": input[\"Received By\"],\n \"Submission ID\": input[\"Submission ID\"]\n }\n};"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},
{
"id": "4ce817b0-2283-438f-82c7-6f4901fffdd3",
"name": "Calculate Updated Current Stock",
"type": "n8n-nodes-base.code",
"position": [
7640,
1840
],
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const existingStock = parseFloat(\n$('Lookup Existing Stock').first().json['Current Stock']\n|| 0);\nconst newQuantity = parseFloat(\n $('Validate Quantity Received').first().json['Quantity Received']);\nconst updatedStock = existingStock + newQuantity;\n\n\n \nreturn {\n json: {\n ...$json,\n \"Updated Current Stock\": updatedStock\n }\n};"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."View on GitHub (pinned to 94007c1445)
Solutions
- Make Quantity Received required and numeric at the form layer (input type=number, min>0).
- Check the exact field name in the arriving payload via the console.log of complete input data already present in the node.
- Trim units: extend the cleaner to also strip letters, or send machine-formatted values from the form.
- If zero-quantity submissions are invalid too, change the check to quantity === null || quantity <= 0.
Example fix
// before
const quantity = getNumber(input["Quantity Received"]);
if (quantity === null) throw new Error(`Invalid quantity: ${input["Quantity Received"]}`);
// after
const quantity = getNumber(input["Quantity Received"]);
if (quantity === null || quantity <= 0) {
throw new Error(`Invalid quantity: ${JSON.stringify(input["Quantity Received"])} (field names present: ${Object.keys(input).join(', ')})`);
} Defensive patterns
Strategy: validation
Validate before calling
const qtyRaw = input['Quantity Received'];
const qtyNum = Number(String(qtyRaw ?? '').replace(/[^\d.-]/g, ''));
if (!Number.isFinite(qtyNum) || qtyNum <= 0) {
throw new Error(`Invalid quantity: ${JSON.stringify(qtyRaw)} (keys: ${Object.keys(input).join(', ')})`);
} Type guard
const isValidQuantity = (v) => {
if (v === undefined || v === null || v === '') return false;
const n = parseFloat(String(v).replace(/[^\d.-]/g, ''));
return Number.isFinite(n) && n > 0;
}; Prevention
- Make quantity required and numeric (min>0) in the submitting form
- Match field names exactly between the form payload and the Code node
- Echo available keys in validation errors
- Validate at the webhook entry so bad data never reaches calculation nodes
When it happens
Trigger: Webhook form submitted with Quantity Received missing, empty string, or a value like 'abc' or ' pieces' that strips to nothing; field name mismatch (form sends 'quantity_received' or 'Qty Received'); value 0 is NOT rejected (parseFloat('0')=0 passes), so this specifically means unparseable input.
Common situations: Google Form / front-end form field renamed or made optional; respondents typing free text into a numeric field; leading/trailing currency or unit words in the value; webhook payload schema drift.
Related errors
- Invalid price: ${input["Unit Price"]}
- Invalid quantity Requested: ${quantityRequested}. Must be gr
- Product ID is missing
- Invalid quantity requested: ${quantityRequested}
- Insufficient stock for ${$('Retrieve Issue Request Details')
AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15).
Data as JSON: /api/errors/e3a03c59041f43d0.
Report an issue: GitHub.