{"record":{"id":"0a629d6035c13dc1","repo":"n8n-io/n8n","slug":"code-mode-api-misuse","errorCode":"CODE_MODE_API_MISUSE","errorMessage":"${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.","messagePattern":"(.+?)uses mode: 'runOnceForEachItem' but calls \\$input\\.(.+?)\\(\\)\\. \\$input\\.(.+?)\\(\\) is only available in runOnceForAllItems \\(the default\\)\\. Switch mode to runOnceForAllItems, or use \\$input\\.item / \\$json for per-item work\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/@n8n/workflow-sdk/src/lint/code-node/js.ts","lineNumber":194,"sourceCode":"\n\tif (sawForbiddenImport) {\n\t\tissues.push(\n\t\t\tlintIssue({\n\t\t\t\tcode: 'CODE_NODE_FORBIDDEN_IMPORT',\n\t\t\t\tmessage:\n\t\t\t\t\t`${namePrefix}Code node imports a module unavailable in the sandbox (luxon, openai, langchain, …). ` +\n\t\t\t\t\t'Use JavaScript `Date`/`Intl`, `$now`/`$today`, existing workflow data, or dedicated AI nodes instead.',\n\t\t\t\tlintTarget: 'jsCode',\n\t\t\t\tnodeName: options.nodeName,\n\t\t\t\tparameterPath: 'jsCode',\n\t\t\t}),\n\t\t);\n\t}\n\n\tif (options.mode === 'runOnceForEachItem' && disallowedInputMethod !== undefined) {\n\t\tissues.push(\n\t\t\tlintIssue({\n\t\t\t\tcode: 'CODE_MODE_API_MISUSE',\n\t\t\t\tmessage:\n\t\t\t\t\t`${namePrefix}uses mode: 'runOnceForEachItem' but calls $input.${disallowedInputMethod}(). ` +\n\t\t\t\t\t`$input.${disallowedInputMethod}() is only available in runOnceForAllItems (the default). ` +\n\t\t\t\t\t'Switch mode to runOnceForAllItems, or use $input.item / $json for per-item work.',\n\t\t\t\tlintTarget: 'jsCode',\n\t\t\t\tnodeName: options.nodeName,\n\t\t\t\tparameterPath: 'jsCode',\n\t\t\t}),\n\t\t);\n\t}\n\n\tif (hasNestedTemplateLiteral(ast)) {\n\t\tissues.push(\n\t\t\tlintIssue({\n\t\t\t\tcode: 'CODE_NESTED_TEMPLATE_LITERAL',\n\t\t\t\tmessage:\n\t\t\t\t\t`${namePrefix}Code node uses nested template literals, which often break after save. ` +\n\t\t\t\t\t'Build multi-line strings with arrays joined by a runtime separator, e.g. ' +","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/lint/code-node/js.ts#L176-L212","documentation":"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.","triggerScenarios":"mode: 'runOnceForEachItem' combined with $input.all(), $input.first(), $input.last(), or $input.itemMatching(0) anywhere in jsCode.","commonSituations":"LLM mixes per-item mode with all-items APIs; developer toggles mode without updating the code body; copied snippet assumes all-items context.","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."],"exampleFix":"// before — mode: 'runOnceForEachItem'\nreturn $input.all().map((i) => i.json.x);\n// after — mode: 'runOnceForAllItems'\nreturn $input.all().map((i) => i.json.x);\n// (or keep per-item mode and use:)\n// return $json.x;","handlingStrategy":"validation","validationCode":"import { lintJsCode } from '@n8n/workflow-sdk/lint/code-node/js';\nconst issues = lintJsCode(jsCode, { mode: 'runOnceForEachItem' });\nif (issues.some((i) => i.code === 'CODE_MODE_API_MISUSE')) {\n  throw new Error('runOnceForEachItem cannot use $input.first/last/all/itemMatching; switch mode or use $input.item.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["lint","code-node","sdk"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}