跳到主要内容

工作流模板

创建新工作流时,可以选择从空工作流开始,也可以使用已有模板1。

模板可以提供:

  • 入门帮助:n8n 可能已经有能满足需求的模板。
  • 可以构建哪些内容的示例
  • 创建自己的工作流时可参考的最佳实践

访问模板 ​

选择 查看模板图标 Templates(模板),查看模板库。

如果使用 n8n 模板库,会跳转到 n8n 网站的工作流页面进行浏览。如果使用组织提供的自定义模板库,则可以在应用内搜索和浏览模板。

将工作流添加到 n8n 模板库 ​

可以将工作流提交到 n8n 模板库。

n8n 正在筹备创作者计划,并开发模板市场。这是持续推进的项目,具体细节可能变化。

提交模板和成为创作者的方法,请参阅 n8n 创作者中心。

自托管 n8n:使用自己的模板库 ​

在环境变量中,将 N8N_TEMPLATES_HOST 设为 API 的基础 URL。

端点 ​

你的 API 必须提供与 n8n 相同的端点和数据结构。

端点如下:

方法路径用途
GET/templates/workflows/<id>获取模板元数据,用于预览和浏览
GET/workflows/templates/<id>获取要导入画布的工作流数据
GET/templates/search搜索工作流模板
GET/templates/collections/<id>获取指定模板集合
GET/templates/collections列出所有模板集合
GET/templates/categories列出所有模板类别
GET/health健康检查端点
注意

重要:需要两种不同的响应格式

两个工作流端点要求不同的响应格式:

  • /templates/workflows/{id}:返回模板本身,其中的 workflow 键包含工作流
  • /workflows/templates/{id}:返回模板包含的工作流

详情请参阅下方的数据结构说明。

查询参数 ​

/templates/search 端点接受以下查询参数:

参数类型说明
page整数要返回的结果页码
rows整数每页最多返回的结果数
category以逗号分隔的字符串列表(类别)要搜索的类别
search字符串搜索词

/templates/collections 端点接受以下查询参数:

参数类型说明
category以逗号分隔的字符串列表(类别)要搜索的类别
search字符串搜索词

数据结构 ​

两个工作流端点的关键区别如下:

// GET /templates/workflows/{id} returns (wrapped):
{
"workflow": {
"id": 123,
"name": "...",
"totalViews": 1000,
// ... see full workflow item schema below
"workflow": { // actual workflow definition
"nodes": [...],
"connections": {}
}
}
}

// GET /workflows/templates/{id} returns (flat):
{
"id": 123,
"name": "...",
"workflow": { // actual workflow definition
"nodes": [...],
"connections": {}
}
}

响应对象的详细数据结构:

显示 workflow 条目数据结构

用于 /templates/workflows/{id} 端点(包裹在 workflow 键中)。

此结构描述在搜索和浏览界面中展示模板所用的元数据。其中包含一个嵌套的 workflow 属性,保存实际可导入的工作流定义。

工作流条目数据结构
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Generated schema for Root",
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"totalViews": {
"type": "number"
},
"price": {},
"purchaseUrl": {},
"recentViews": {
"type": "number"
},
"createdAt": {
"type": "string"
},
"user": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"verified": {
"type": "boolean"
}
},
"required": [
"username",
"verified"
]
},
"nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"icon": {
"type": "string"
},
"name": {
"type": "string"
},
"codex": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"details": {
"type": "string"
},
"resources": {
"type": "object",
"properties": {
"generic": {
"type": "array",
"items": {
"type": "object",
"properties": {
"url": {
"type": "string"
},
"icon": {
"type": "string"
},
"label": {
"type": "string"
}
},
"required": [
"url",
"label"
]
}
},
"primaryDocumentation": {
"type": "array",
"items": {
"type": "object",
"properties": {
"url": {
"type": "string"
}
},
"required": [
"url"
]
}
}
},
"required": [
"primaryDocumentation"
]
},
"categories": {
"type": "array",
"items": {
"type": "string"
}
},
"nodeVersion": {
"type": "string"
},
"codexVersion": {
"type": "string"
}
},
"required": [
"categories"
]
}
}
},
"group": {
"type": "string"
},
"defaults": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"color": {
"type": "string"
}
},
"required": [
"name"
]
},
"iconData": {
"type": "object",
"properties": {
"icon": {
"type": "string"
},
"type": {
"type": "string"
},
"fileBuffer": {
"type": "string"
}
},
"required": [
"type"
]
},
"displayName": {
"type": "string"
},
"typeVersion": {
"type": "number"
},
"nodeCategories": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
]
}
}
},
"required": [
"id",
"icon",
"name",
"codex",
"group",
"defaults",
"iconData",
"displayName",
"typeVersion"
]
}
},
"description": {
"type": "string"
},
"image": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"url": {
"type": "string"
}
}
}
},
"categories": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
}
}
}
},
"workflowInfo": {
"type": "object",
"properties": {
"nodeCount": {
"type": "number"
},
"nodeTypes": {
"type": "object"
}
}
},
"workflow": {
"type": "object",
"properties": {
"nodes": {
"type": "array"
},
"connections": {
"type": "object"
},
"settings": {
"type": "object"
},
"pinData": {
"type": "object"
}
},
"required": [
"nodes",
"connections"
]
}
},
"required": [
"id",
"name",
"totalViews",
"createdAt",
"user",
"nodes",
"workflow"
]
}
显示 category 条目数据结构
类别条目数据结构
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
]
}
显示 collection 条目数据结构
集合条目数据结构
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": "number"
},
"rank": {
"type": "number"
},
"name": {
"type": "string"
},
"totalViews": {},
"createdAt": {
"type": "string"
},
"workflows": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
}
},
"required": [
"id"
]
}
},
"nodes": {
"type": "array",
"items": {}
}
},
"required": [
"id",
"rank",
"name",
"totalViews",
"createdAt",
"workflows",
"nodes"
]
}

也可以交互式探索 n8n 的 API 端点:

https://api.n8n.io/templates/categories https://api.n8n.io/templates/collections https://api.n8n.io/templates/search https://api.n8n.io/health

可以联系我们获取更多支持。

相关资源 ​

Footnotes​

  1. n8n 模板是由 n8n 和社区成员设计的预构建工作流,可以导入自己的 n8n 实例。使用模板时,可能需要填写凭据并按需求调整配置。 ↩

本文为社区中文翻译。查看对应英文原文