Skip to content

声明式参数

这些是声明式节点的节点基础文件可用的参数。

本文档提供了一些简短的代码片段,帮助您理解代码结构和概念。有关构建节点的完整演示(包括实际代码示例),请参阅构建声明式节点

有关所有节点可用的参数,请参阅标准参数

对象|可选

包含对象。您可以使用它来查询服务以获取用户特定的设置,然后返回这些设置并将其呈现在 GUI 中,以便用户可以在后续查询中使用它们。该对象必须包含有关如何查询服务的路由信息,以及定义如何处理返回选项的输出设置。例如:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
methods : {
	loadOptions: {
		routing: {
			request: {
				url: '/webhook/example-option-parameters',
				method: 'GET',
			},
			output: {
				postReceive: [
					{
						// When the returned data is nested under another property
						// Specify that property key
						type: 'rootProperty',
						properties: {
							property: 'responseData',
						},
					},
					{
						type: 'setKeyValue',
						properties: {
							name: '={{$responseItem.key}} ({{$responseItem.value}})',
							value: '={{$responseItem.value}}',
						},
					},
					{
						// If incoming data is an array of objects, sort alphabetically by key
						type: 'sort',
						properties: {
							key: 'name',
						},
					},
				],
			},
		},
	}
},

routing#

对象|必填

是在操作和输入字段对象中使用的数组对象。它包含 API 调用的详细信息。

以下代码示例来自声明式教程。它设置了与 NASA API 的集成。它展示了如何使用它来设置基本的 API 调用详细信息,以及如何为每个操作添加信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
description: INodeTypeDescription = {
  // Other node info here
  requestDefaults: {
			baseURL: 'https://api.nasa.gov',
			url: '',
			headers: {
				Accept: 'application/json',
				'Content-Type': 'application/json',
			},
		},
    properties: [
      // Resources here
      {
        displayName: 'Operation'
        // Other operation details
        options: [
          {
            name: 'Get'
            value: 'get',
            description: '',
            routing: {
              request: {
                method: 'GET',
                url: '/planetary/apod'
              }
            }
          }
        ]
      }
    ]
}

version#

数字数组|可选

如果您的节点只有一个版本,则可以使用数字。如果您想支持多个版本,请将其转换为一个数组,其中包含每个节点版本的数字。

n8n 支持两种节点版本控制方法,但声明式节点必须使用轻量级版本控制方法。有关更多信息,请参阅节点版本控制