Create custom n8n nodes with ease
1 of 6 steps completed
Step 1 of 6
6 steps remaining
Configure the basic information for your n8n node
Define the core properties that identify your node
Used for file names and class names (camelCase)
Shown in the n8n interface
Optional: Place SVG file in the nodes folder
Preview and export your n8n node files
import {
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
NodeConnectionType,
NodeOperationError,
} from 'n8n-workflow';
export class implements INodeType {
description: INodeTypeDescription = {
displayName: '',
name: '',
icon: 'file:.svg',
group: ['transform'],
version: 1.0.0,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: '',
defaults: {
name: '',
},
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
credentials: [
{
name: 'Api',
required: false,
},
],
requestDefaults: {
baseURL: 'https://api.example.com',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
],
default: '',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [''],
},
},
options: [
],
default: '',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
for (let i = 0; i < items.length; i++) {
try {
const resource = this.getNodeParameter('resource', i) as string;
const operation = this.getNodeParameter('operation', i) as string;
let responseData;
if (resource === '') {
if (operation === '') {
responseData = await this.makeRoutingRequest({
itemIndex: i,
additionalKeys: {},
});
}
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as any),
{ itemData: { item: i } }
);
returnData.push(...executionData);
} catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData: { item: i } }
);
returnData.push(...executionErrorData);
} else {
throw error;
}
}
}
return [returnData];
}
}