n8n 中文文档

工作流程模板

创建新工作流程时,您可以选择是从空工作流程开始,还是使用现有模板[^1]。

模板提供:

  • 帮助入门:n8n 可能已经有一个可以满足您需要的模板。
  • 您可以构建的示例
  • 创建您自己的工作流程的最佳实践

访问模板

选择 View templates icon Templates 模板 查看模板库。

如果您使用n8n的模板库,这将带您浏览n8n网站上的工作流程。如果您使用组织提供的自定义库,您将能够在应用程序中搜索和浏览模板。

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

要把自己的工作流分享到模板库,请按照创建工作流模板操作。该指南涵盖质量要求、测试、文档和提交步骤。

自托管n8n:使用自己的库

在环境变量中,将 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

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

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

相关资源

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