Zie619/n8n-workflows · error · Error
Invalid quantity Requested: ${quantityRequested}. Must be gr
Error message
Invalid quantity Requested: ${quantityRequested}. Must be greater than 0 What it means
Thrown by 'Validate Issue Request Data' when `Quantity Requested` from the issue-request webhook is <= 0. The check runs on the raw input (no parsing), so undefined also compares <= 0 in JS (undefined <= 0 is false - actually undefined converts to NaN, so NaN <= 0 is false; but '0', empty string '', and 0 all pass the throw). Empty string '' <= 0 is true, so blank submissions throw here.
Source
Thrown at workflows/Code/0926_Code_Webhook_Create_Webhook.json:1591
"parameters": {
"sendTo": "example@gmail.com",
"message": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Low Stock Alert</title>\n <style>\n body {\n font-family: Arial, sans-serif;\n line-height: 1.6;\n color: #333;\n background-color: #f4f4f4;\n margin: 0;\n padding: 0;\n }\n .container {\n width: 80%;\n max-width: 600px;\n margin: 20px auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 8px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h2 {\n color: #e74c3c;\n text-align: center;\n }\n p {\n margin: 10px 0;\n }\n .alert-message {\n background-color: #ffe6e6;\n padding: 15px;\n border-left: 4px solid #e74c3c;\n margin: 20px 0;\n font-weight: bold;\n }\n ul {\n list-style-type: none;\n padding: 0;\n margin: 20px 0;\n background-color: #f9f9f9;\n padding: 15px;\n border-left: 4px solid #3498db;\n }\n ul li {\n margin: 8px 0;\n }\n ul li strong {\n display: inline-block;\n width: 150px;\n }\n .action {\n text-align: center;\n margin: 20px 0;\n }\n .btn {\n display: inline-block;\n padding: 10px 20px;\n text-decoration: none;\n color: #fff;\n background-color: #3498db;\n border-radius: 5px;\n font-weight: bold;\n }\n .footer {\n text-align: center;\n margin-top: 20px;\n font-size: 0.9em;\n color: #777;\n }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <h2>Low Stock Alert</h2>\n <p>Dear Stock Manager,</p>\n\n <p>We have detected a low stock level for the following material:</p>\n\n <div class=\"alert-message\">\n {{ $json[\"Alert Message\"] }}\n </div>\n\n <ul>\n <li><strong>Product ID:</strong> {{ $json[\"Product ID\"] }}</li>\n <li><strong>Material:</strong> {{ $json[\"Material Name\"] }}</li>\n <li><strong>Current Stock:</strong> {{ $json[\"Current Stock\"] }} {{ $json[\"Measurement Unit\"] }}</li>\n <li><strong>Minimum Stock:</strong> {{ $json[\"Minimum Stock Level\"] }} {{ $json[\"Measurement Unit\"] }}</li>\n </ul>\n\n <div class=\"action\">\n <p>Please take action to reorder this material.</p>\n <a href=\"{{ $env.WEBHOOK_URL }}\" class=\"btn\">Reorder Now</a>\n </div>\n\n <div class=\"footer\">\n <p>Regards,<br>Your Company</p>\n </div>\n </div>\n</body>\n</html>",
"options": {},
"subject": "Low Stock Alert: Immediate Action Required"
},
"typeVersion": 2.1,
"notes": "This gmail node performs automated tasks as part of the workflow."
},
{
"id": "ac8781e9-f694-467d-b40b-95bdbab98880",
"name": "Validate Issue Request Data",
"type": "n8n-nodes-base.code",
"position": [
6340,
3400
],
"parameters": {
"jsCode": "const input = $input.all()[0].json;\nconst quantityRequested= input[\"Quantity Requested\"];\n\nif (quantityRequested <= 0) throw new Error(`Invalid quantity Requested: ${quantityRequested}. Must be greater than 0`);\n\nreturn { json: input };"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},
{
"id": "6d88db70-6b4f-47c5-8093-ab339762edbe",
"name": "Verify Requested Quantity",
"type": "n8n-nodes-base.code",
"position": [
6560,
3400
],
"parameters": {
"jsCode": "const input = $input.all()[0].json;\nconst quantityRequested = input[\"Quantity Requested\"];\nif (!input[\"Product ID\"]) throw new Error(\"Product ID is missing\");\nif (quantityRequested <= 0) throw new Error(`Invalid quantity requested: ${quantityRequested}`);\nif (!input[\"Submission ID\"]) throw new Error(\"Submission ID is missing\");\nreturn { json: input };"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},View on GitHub (pinned to 94007c1445)
Solutions
- Parse first, then validate: use Number.isFinite and > 0 so both garbage and non-positive values are caught.
- Enforce min=1 and required on the quantity field in the request form.
- Include the raw value and its type in the error for diagnosis.
- Route failures to an error-response branch that tells the requester instead of failing silently.
Example fix
// before
const quantityRequested = input["Quantity Requested"];
if (quantityRequested <= 0) throw new Error(`Invalid quantity Requested: ${quantityRequested}. Must be greater than 0`);
// after
const quantityRequested = Number(input["Quantity Requested"]);
if (!Number.isFinite(quantityRequested) || quantityRequested <= 0) {
throw new Error(`Invalid quantity Requested: ${JSON.stringify(input["Quantity Requested"])}. Must be a number greater than 0`);
} Defensive patterns
Strategy: validation
Validate before calling
const quantityRequested = Number(input['Quantity Requested']);
if (!Number.isFinite(quantityRequested) || quantityRequested <= 0) {
throw new Error(`Invalid quantity Requested: ${JSON.stringify(input['Quantity Requested'])}. Must be greater than 0`);
} Type guard
const isValidRequestedQty = (v) => {
const n = Number(v);
return Number.isFinite(n) && n > 0;
}; Prevention
- Convert to Number before comparing - raw '<= 0' lets NaN slip through
- Set min=1 and required on the request form
- Echo the raw value (JSON.stringify) in the error
- Route invalid submissions to a user-facing error response branch
When it happens
Trigger: Submission with Quantity Requested = 0, '0', or '' (empty string); a -1 test value; input.readOnly draft submissions; type coercion surprises: '5abc' is NaN so it does NOT throw here and fails later.
Common situations: Request form allows 0 or blank quantity; form validation missing client-side; numeric field submitted as text with empty value.
Related errors
- Invalid quantity requested: ${quantityRequested}
- Product ID is missing
- Insufficient stock for ${$('Retrieve Issue Request Details')
- Invalid quantity: ${input["Quantity Received"]}
- Submission ID is missing
AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15).
Data as JSON: /api/errors/014c8e233e3f49c4.
Report an issue: GitHub.