Zie619/n8n-workflows · error · Error
Invalid price: ${input["Unit Price"]}
Error message
Invalid price: ${input["Unit Price"]} What it means
Thrown by 'Calculate Total Price' when `Unit Price` cannot be parsed to a number by getNumber. Currency symbols, commas, and spaces are stripped before parseFloat, so this fires only when the remaining string is empty or non-numeric (NaN) or the field is absent.
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 Unit Price a required numeric field in the submitting form.
- Verify the exact key via the node's existing console.log of full input.
- Accept common formats explicitly: strip thousands separators correctly ('1,234.56' -> 1234.56) before parseFloat.
- Guard downstream: skip the Google Sheets append and notify the submitter instead of failing the run.
Example fix
// before
const unitPrice = getNumber(input["Unit Price"]);
if (unitPrice === null) throw new Error(`Invalid price: ${input["Unit Price"]}`);
// after
const parsePrice = (v) => {
if (typeof v !== 'string' && typeof v !== 'number') return null;
const cleaned = String(v).replace(/[,$\s]/g, '');
const n = Number(cleaned);
return Number.isFinite(n) && n >= 0 ? n : null;
};
const unitPrice = parsePrice(input["Unit Price"]);
if (unitPrice === null) throw new Error(`Invalid price: ${JSON.stringify(input["Unit Price"])}`); Defensive patterns
Strategy: validation
Validate before calling
const priceRaw = input['Unit Price'];
const priceNum = Number(String(priceRaw ?? '').replace(/[,$\s]/g, ''));
if (!Number.isFinite(priceNum) || priceNum < 0) {
throw new Error(`Invalid price: ${JSON.stringify(priceRaw)}`);
} Type guard
const isValidPrice = (v) => {
if (typeof v !== 'string' && typeof v !== 'number') return false;
const n = Number(String(v).replace(/[,$\s]/g, ''));
return Number.isFinite(n) && n >= 0;
}; Prevention
- Require numeric price input in the form; strip commas/currency in one shared parser
- Confirm the exact field key via the node's full-input log
- Reject or clean 'per unit'-style free text before submission
- Guard the sheets append behind validation success
When it happens
Trigger: Unit Price missing from the webhook payload; value like 'per unit' or 'N/A'; field named differently in the form; value is an object/array because the form sent nested JSON.
Common situations: Price field optional in the form; free-text price inputs; currency strings that strip to nothing ('¥' alone); schema changes after form edits.
Related errors
- Invalid quantity: ${input["Quantity Received"]}
- Invalid quantity Requested: ${quantityRequested}. Must be gr
- Product ID is missing
- Invalid quantity requested: ${quantityRequested}
- Submission ID is missing
AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15).
Data as JSON: /api/errors/526caaf6be8d3047.
Report an issue: GitHub.