[//]: # "File generated from a template. Do not edit this file directly." # node-execute-block-error-missing-item-index In the operations in the `execute()` method in a node, `NodeApiError` and `NodeOperationError` must specify `itemIndex` as the third argument. 📋 This rule is part of the `plugin:n8n-nodes-base/nodes` config. ## Examples ❌ Example of **incorrect** code: ```js class TestNode { async execute() { const items = this.getInputData(); const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; let responseData; for (let i = 0; i < items.length; i++) { try { if (resource === 'ticket') { if (operation === 'create') { responseData = await serviceApiRequest.call(this, 'POST', '/tickets', body); throw new NodeOperationError(this.getNode(), "Error!"); } } } catch (error) { if (this.continueOnFail()) { // ... } } } return [returnData]; } } class TestNode { async execute() { const items = this.getInputData(); const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; let responseData; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { try { if (resource === 'ticket') { if (operation === 'create') { responseData = await serviceApiRequest.call(this, 'POST', '/tickets', body); throw new NodeOperationError(this.getNode(), "Error!"); } } } catch (error) { if (this.continueOnFail()) { // ... } } } return [returnData]; } } class TestNode { async execute() { const items = this.getInputData(); const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; let responseData; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { try { if (resource === 'ticket') { if (operation === 'create') { responseData = await serviceApiRequest.call(this, 'POST', '/tickets', body); throw new NodeOperationError(this.getNode(), "Error!", { test: 123 }); } } } catch (error) { if (this.continueOnFail()) { // ... } } } return [returnData]; } } class TestNode { async execute() { const items = this.getInputData(); const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; let responseData; for (let i = 0; i < items.length; i++) { try { if (resource === 'ticket') { if (operation === 'create') { responseData = await serviceApiRequest.call(this, 'POST', '/tickets', body); throw new NodeOperationError(this.getNode(), "Error!", { test: 123 }); } } } catch (error) { if (this.continueOnFail()) { // ... } } } return [returnData]; } } ``` ✅ Example of **correct** code: ```js class TestNode { async execute() { const items = this.getInputData(); const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; let responseData; for (let i = 0; i < items.length; i++) { try { if (resource === 'ticket') { if (operation === 'create') { responseData = await serviceApiRequest.call(this, 'POST', '/tickets', body); throw new NodeOperationError(this.getNode(), "Error!", { itemIndex: i }); } } } catch (error) { if (this.continueOnFail()) { // ... } } } return [returnData]; } } ``` ## Links - [Rule source](../../lib/rules/node-execute-block-error-missing-item-index.ts) - [Test source](../../tests/node-execute-block-error-missing-item-index.test.ts)