I’m working on a custom n8n node for my company. Right now, I have two action nodes (authenticate and upload file) that show up separately when I search for the company node. But I want them to be part of one main node, like how S3 does it.
Here’s what I’ve tried:
- In my
main.node.ts
, I defined a Company
class with properties for both actions.
- In
package.json
, I listed both action nodes under the main
key.
"nodes": {
"main": [
"dist/nodes/main/authenticate.node.js",
"dist/nodes/main/uploadFile.node.js"
]
}
But this setup still shows two separate nodes instead of one main node with a dropdown for actions. I also tried creating separate auth.node.ts
and upload.node.ts
files, but that just made two core nodes.
Any ideas on how to get that S3-style structure with one main node and multiple actions inside it? Thanks!
hey there! i’ve struggled with this too. one thing that worked for me was using the description
property in ur node definition. try somethin like:
export class Company {
description = {
displayName: 'Company',
name: 'company',
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
options: [
{name:'Authenticate',value:'authenticate'},
{name:'Upload File',value:'uploadFile'}
],
default: 'authenticate'
}
]
}
}
hope that helps!
I’ve been in your shoes before, and I can tell you it’s definitely possible to structure your custom node like S3. The key is using the ‘resourceDescription’ property in your main node file.
Here’s what worked for me:
- Create a single main.node.ts file
- Define your Company class with a description object
- Use the ‘properties’ array to define your operations
Your main.node.ts might look something like this:
export class Company implements INodeType {
description = {
displayName: 'Company',
name: 'company',
icon: 'file:company.svg',
group: ['transform'],
version: 1,
description: 'Interact with Company API',
defaults: { name: 'Company' },
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
options: [
{ name: 'Authenticate', value: 'authenticate' },
{ name: 'Upload File', value: 'uploadFile' }
],
default: 'authenticate'
}
]
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const operation = this.getNodeParameter('operation', 0) as string;
switch (operation) {
case 'authenticate':
// Authentication logic
break;
case 'uploadFile':
// File upload logic
break;
}
// Return result
}
}
This approach should give you a single node with multiple operations to choose from. Good luck with your project!
I’ve encountered a similar challenge while developing custom nodes. One effective approach is to utilize the ‘resourceDescription’ property in your node definition. This allows you to create a single node with multiple operations.
Here’s a basic structure you could try:
export class Company implements INodeType {
description: INodeTypeDescription = {
displayName: 'Company',
name: 'company',
icon: 'file:company.svg',
group: ['transform'],
version: 1,
description: 'Interact with Company API',
defaults: {
name: 'Company',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'companyApi',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
options: [
{
name: 'Authenticate',
value: 'authenticate',
},
{
name: 'Upload File',
value: 'uploadFile',
},
],
default: 'authenticate',
description: 'The operation to perform.',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
// Implementation logic here
}
}
This structure should create a single node with a dropdown for selecting different operations.