n8n 中文文档

配置自定义工作流模板库

n8n 提供了一个工作流程模板库[^1]。当自托管 n8n 时,您可以:

  • 继续使用n8n的工作流程模板库(这是默认行为)
  • 禁用工作流程模板
  • 创建您自己的工作流程模板库

禁用工作流程模板

在环境变量中,将 N8N_TEMPLATES_ENABLED 设置为 false。

使用您自己的工作流程模板库

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

端点

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

端点是:

方法 路径 目的
获取 /templates/workflows/<id> 获取模板元数据以进行预览/浏览
获取 /workflows/templates/<id> 获取工作流程数据以导入到画布上
获取 /templates/search 搜索工作流程模板
获取 /templates/collections/<id> 获取特定模板集合
获取 /templates/collections 列出所有模板集合
获取 /templates/categories 列出所有模板类别
获取 /health 健康检查端点

警告

Critical: Two different response formats required 关键:需要两种不同的响应格式

两个工作流端点需要 different response formats 不同的响应格式:

  • /templates/workflows/{id} /模板/工作流程/{id}:返回模板本身,其中包括workflow密钥中的工作流程
  • /workflows/templates/{id} /工作流程/模板/{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": {}
  }
}

响应对象的详细架构:

显示 工作流程 项目数据架构 由 `/templates/workflows/{id}` 端点使用(封装在 `workflow` 密钥中)。 此架构描述了用于在搜索/浏览 UI 中显示模板的模板元数据。它包括一个嵌套的 `workflow` 属性,其中包含实际的可导入工作流定义。 ```json title="Workflow item data schema" { "$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" ] }

</details>

<details>

<summary>显示 <code>类别</code> 项目数据架构</summary>

```json title="Category item data schema"
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name"
  ]
}
显示 集合 项目数据架构 ```json title="Collection item data schema" { "$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

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

将您的工作流程添加到 n8n 库

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

n8n 正在开发创作者计划,并开发模板市场。这是一个正在进行的项目,详细信息可能会发生变化。

请参考 n8n Creator hub{:target=_blank .external-link} 了解如何提交模板和成为创作者的信息。

[^1]:n8n 模板是由 n8n 和社区成员设计的预构建工作流程,您可以将其导入到您的 n8n 实例中。使用模板时,您可能需要填写凭据并调整配置以满足您的需求。

相关资源

不想自己部署和维护 n8n?n8ncn 托管 n8n 云服务:开通账号即可使用,不用买服务器;也可以在 n8ncn 工作流库 找现成的中文工作流。