n8n-io/n8n · warning
CODE_MODE_API_MISUSE
CODE_MODE_API_MISUSE
Error message
${namePrefix}uses mode: 'runOnceForEachItem' but calls $input.${disallowedInputMethod}(). $input.${disallowedInputMethod}() is only available in runOnceForAllItems (the default). Switch mode to runOnceForAllItems, or use $input.item / $json for per-item work. What it means
CODE_MODE_API_MISUSE is a lint issue. When mode is 'runOnceForEachItem', lintJsCode() flags any call to $input.first(), $input.last(), $input.all(), or $input.itemMatching(n) — these only exist in runOnceForAllItems. The walker matches $input.<method>() specifically.
Source
Thrown at packages/@n8n/workflow-sdk/src/lint/code-node/js.ts:194
if (sawForbiddenImport) {
issues.push(
lintIssue({
code: 'CODE_NODE_FORBIDDEN_IMPORT',
message:
`${namePrefix}Code node imports a module unavailable in the sandbox (luxon, openai, langchain, …). ` +
'Use JavaScript `Date`/`Intl`, `$now`/`$today`, existing workflow data, or dedicated AI nodes instead.',
lintTarget: 'jsCode',
nodeName: options.nodeName,
parameterPath: 'jsCode',
}),
);
}
if (options.mode === 'runOnceForEachItem' && disallowedInputMethod !== undefined) {
issues.push(
lintIssue({
code: 'CODE_MODE_API_MISUSE',
message:
`${namePrefix}uses mode: 'runOnceForEachItem' but calls $input.${disallowedInputMethod}(). ` +
`$input.${disallowedInputMethod}() is only available in runOnceForAllItems (the default). ` +
'Switch mode to runOnceForAllItems, or use $input.item / $json for per-item work.',
lintTarget: 'jsCode',
nodeName: options.nodeName,
parameterPath: 'jsCode',
}),
);
}
if (hasNestedTemplateLiteral(ast)) {
issues.push(
lintIssue({
code: 'CODE_NESTED_TEMPLATE_LITERAL',
message:
`${namePrefix}Code node uses nested template literals, which often break after save. ` +
'Build multi-line strings with arrays joined by a runtime separator, e.g. ' +View on GitHub (pinned to 5ac6606e81)
Solutions
- Switch the Code node mode to runOnceForAllItems (the default) if you need $input.all()/first()/last().
- Keep runOnceForEachItem and use $input.item / $json for per-item work instead.
Example fix
// before — mode: 'runOnceForEachItem' return $input.all().map((i) => i.json.x); // after — mode: 'runOnceForAllItems' return $input.all().map((i) => i.json.x); // (or keep per-item mode and use:) // return $json.x;
Defensive patterns
Strategy: validation
Validate before calling
import { lintJsCode } from '@n8n/workflow-sdk/lint/code-node/js';
const issues = lintJsCode(jsCode, { mode: 'runOnceForEachItem' });
if (issues.some((i) => i.code === 'CODE_MODE_API_MISUSE')) {
throw new Error('runOnceForEachItem cannot use $input.first/last/all/itemMatching; switch mode or use $input.item.');
} Prevention
- In runOnceForEachItem use $input.item / $json only.
- If you need $input.all()/first()/last(), set mode to runOnceForAllItems.
- Lint with the same mode the node will run in.
When it happens
Trigger: mode: 'runOnceForEachItem' combined with $input.all(), $input.first(), $input.last(), or $input.itemMatching(0) anywhere in jsCode.
Common situations: LLM mixes per-item mode with all-items APIs; developer toggles mode without updating the code body; copied snippet assumes all-items context.
Related errors
- CODE_NODE_NETWORK_CALL
- CODE_NODE_FORBIDDEN_IMPORT
- CODE_NESTED_TEMPLATE_LITERAL
- CODE_NODE_NETWORK_CALL
- SDK_AS_CONST
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/0a629d6035c13dc1.
Report an issue: GitHub.