N8n node development problem

Now i develop node for notes service (like notion, evernote and others). I need load text, title and other fields from picked document from resource locator, how i can make it?

Hey @teuchezh,

It is always worth checking other nodes that do this as I often find those examples are a lot easier to follow.

The quick option is you would need to use the loadOptionsMethod and in there get your parameter, the Notion Node is pretty good for this if you wanted one to follow.

Everything is so, I draw a lot of useful information from the Notion node, because a lot is not documented. But in this particular case, I’m stuck

Hey @teuchezh,

Did you find the loadOptionsMethod? I recently did something similar when I made a Baserow trigger node, Take a look at n8n-nodes-baserow-trigger/BaserowTrigger.node.ts at main · Joffcom/n8n-nodes-baserow-trigger · GitHub and see if it helps as it is less complex than the Notion node.

Thanks for the answer, in general I understood how it works, but I have not yet solved the problem. In your example, you are requesting a database ID in the api, but how is the comparison of the fields in databaseId and the fields received in the response from the api going?

Not sure I understand, But I will give it a go anyway.

So for my node the Table IDs is being pulled from an API based on the database ID value, So this is my Table Name selector field which needs a value in the field above it which is called datebaseId, once that is there we call loadOptionsMethod and tell it we want getTableIds.

{
  displayName: 'Table Name or ID',
  name: 'tableId',
  type: 'options',
  default: '',
  required: true,
  description:
    'Table to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
  typeOptions: {
    loadOptionsDependsOn: ['databaseId'],
    loadOptionsMethod: 'getTableIds',
  },
},

So to load our options we have the function here which is using this.getNodeParameter() to get the value of the databaseId field then it is being passed to the API I am using and with the result I am returning it as an object which is an array similar to [{name: x, value: y}]

methods = {
    loadOptions: {
        async getTableIds(this: ILoadOptionsFunctions) {
            const databaseId = this.getNodeParameter('databaseId', 0) as string;
            const endpoint = `/api/database/tables/database/${databaseId}/`;
            const tables = (await baserowApiRequest.call(
                this,
                'GET',
                endpoint,
            )) as LoadedResource[];
            return toOptions(tables);
        }
    }
};

Hopefully this helps or I have massively misunderstood what you are trying to do :slight_smile:

Yes, you got it right, here is my code below.
The code works, but nothing is substituted in the required fields.

		loadOptions: {
			async getDocumentProperties(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
				const returnData: INodePropertyOptions[] = [];
				const documentId = this.getCurrentNodeParameter('documentId', {
					extractValue: true,
				}) as string;
				const { data } = await apiRequest.call(this, 'POST', `/documents.info`, {
					id: documentId,
				});
				for (const key of Object.keys(data)) {
					returnData.push({
						name: `${key}`,
						value: `${data[key]}`,
					});
				}
				console.log(returnData);
				return returnData;
			},
		}
	{
		displayName: 'Title',
		name: 'title',
		type: 'string',
		default: '',
		required: true,
		typeOptions: {
			loadOptionsMethod: 'getDocumentProperties',
			loadOptionsDependsOn: ['documentId'],
		},
		displayOptions: {
			show: {
				version: [1],
				resource: ['document'],
				operation: ['create', 'update'],
			},
		},
		description: 'The title of the document',
	},

And here is what is inside the returnData array:

[
  {
    name: "id",
    value: "76ff8f26-c55b-4ab5-b32b-19431af9427a",
  },
  {
    name: "url",
    value: "/doc/alo-7TAYK8tHHr",
  },
  {
    name: "urlId",
    value: "7TAYK8tHHr",
  },
  {
    name: "title",
    value: "one two three",
  },
  {
    name: "type",
    value: "document",
  },
  {
    name: "properties",
    value: "null",
  },
  {
    name: "text",
    value: "ааааааааааа",
  },
....
]

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.