跳到主要内容

声明式参数#

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

本文档提供简短代码片段以帮助理解代码结构和概念。如需获取包含实际代码示例的完整节点构建指南,请参阅构建声明式节点

所有节点通用参数请参阅标准参数

methodsloadOptions#

对象类型 | 可选参数

methods 包含 loadOptions 对象。您可以通过 loadOptions 查询服务以获取用户特定设置,随后返回这些设置并在图形界面中渲染,使用户能将其纳入后续查询。该对象必须包含用于查询服务的路由信息,以及定义如何处理返回选项的输出设置。例如:

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#

对象类型 | 必需参数

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

以下代码示例源自声明式风格教程,展示了如何建立与 NASA API 的集成。该示例演示了如何使用 requestDefaults 配置基础 API 调用参数,并通过 routing 为每个操作添加特定信息。

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 提供两种节点版本控制方法,但声明式节点必须采用轻量级版本控制方案。详细信息请参阅节点版本控制