Skip to content

Webhook 节点#

¥Webhook node

使用 Webhook 节点创建 webhooks,该节点可在事件发生时接收来自应用和服务的数据。这是一个触发节点,这意味着它可以启动一个 n8n 工作流。这使得服务能够连接到 n8n 并运行工作流。

¥Use the Webhook node to create webhooks, which can receive data from apps and services when an event occurs. It's a trigger node, which means it can start an n8n workflow. This allows services to connect to n8n and run a workflow.

当你想要接收数据并基于数据运行工作流时,可以使用 Webhook 节点作为工作流的触发器。Webhook 节点也支持返回工作流结束时生成的数据。这使得它可用于构建处理数据并返回结果的工作流,例如 API 端点。

¥You can use the Webhook node as a trigger for a workflow when you want to receive data and run a workflow based on the data. The Webhook node also supports returning the data generated at the end of a workflow. This makes it useful for building a workflow to process data and return the results, like an API endpoint.

Webhook 允许你从没有专用应用触发节点的服务触发工作流。

¥The webhook allows you to trigger workflows from services that don't have a dedicated app trigger node.

工作流开发流程#

¥Workflow development process

n8n 为测试和生产环境提供不同的 Webhook URL。测试 URL 包含一个用于监听测试事件的选项。有关构建、测试 Webhook 节点并将其部署到生产环境的更多信息,请参阅 工作流开发

¥n8n provides different Webhook URLs for testing and production. The testing URL includes an option to Listen for test event. Refer to Workflow development for more information on building, testing, and shifting your Webhook node to production.

节点参数#

¥Node parameters

使用这些参数来配置你的节点。

¥Use these parameters to configure your node.

Webhook URL#

Webhook 节点有两个 Webhook URL:测试和生产环境。n8n 在节点面板顶部显示 URL。

¥The Webhook node has two Webhook URLs: test and production. n8n displays the URLs at the top of the node panel.

选择“测试 URL”或“生产 URL”以切换 n8n 显示的 URL。

¥Select Test URL or Production URL to toggle which URL n8n displays.

Sample Webhook URLs in the Webhook node's Parameters tab display a Test URL and Production URL
Sample Webhook URLs in the Webhook node's Parameters tab
  • 测试:当你选择“监听测试事件”或“执行工作流”(如果工作流未激活)时,n8n 会注册一个测试 Webhook。当你调用 Webhook URL 时,n8n 会在工作流中显示数据。

¥Test: n8n registers a test webhook when you select Listen for Test Event or Execute workflow, if the workflow isn't active. When you call the webhook URL, n8n displays the data in the workflow.

  • 生产:激活工作流时,n8n 会注册一个生产环境 Webhook。使用生产环境 URL 时,n8n 不会在工作流中显示数据。你仍然可以查看生产环境执行的工作流数据:在工作流中选择“执行”选项卡,然后选择要查看的工作流执行。

¥Production: n8n registers a production webhook when you activate the workflow. When using the production URL, n8n doesn't display the data in the workflow. You can still view workflow data for a production execution: select the Executions tab in the workflow, then select the workflow execution you want to view.

HTTP 方法#

¥HTTP Method

Webhook 节点支持标准 HTTP 请求方法

¥The Webhook node supports standard HTTP Request Methods:

  • DELETE

  • GET

  • HEAD

  • PATCH

  • POST

  • PUT

Webhook max payload

1
The webhook maximum payload size is 16MB.

如果你自行托管 n8n,可以使用 端点环境变量N8N_PAYLOAD_SIZE_MAX 更改此设置。

¥If you're self-hosting n8n, you can change this using the endpoint environment variable N8N_PAYLOAD_SIZE_MAX.

路径#

¥Path

默认情况下,此字段包含一个随机生成的 Webhook URL 路径,以避免与其他 Webhook 节点冲突。

¥By default, this field contains a randomly generated webhook URL path, to avoid conflicts with other webhook nodes.

你可以手动指定 URL 路径,包括添加路由参数。例如,如果你使用 n8n 来构建 API 原型并希望使用一致的端点 URL,则可能需要这样做。

¥You can manually specify a URL path, including adding route parameters. For example, you may need to do this if you use n8n to prototype an API and want consistent endpoint URLs.

“路径”字段可以采用以下格式:

¥The Path field can take the following formats:

  • /:variable

  • /path/:variable

  • /:variable/path

  • /:variable1/path/:variable2

  • /:variable1/:variable2

支持的身份验证方法#

¥Supported authentication methods

你可以要求任何调用你的 Webhook URL 的服务进行身份验证。选择以下身份验证方法:

¥You can require authentication for any service calling your webhook URL. Choose from these authentication methods:

  • 基本身份验证

¥Basic auth

  • 标头身份验证

¥Header auth

  • JWT 身份验证

¥JWT auth

¥None

有关设置每种凭证类型的更多信息,请参阅 Webhook 凭据

¥Refer to Webhook credentials for more information on setting up each credential type.

响应#

¥Respond

  • 立即:Webhook 节点会返回响应代码和消息“工作流已启动”。

¥Immediately: The Webhook node returns the response code and the message Workflow got started.

  • 最后一个节点完成时:Webhook 节点会返回响应代码和工作流中最后一个执行节点的数据输出。

¥When Last Node Finishes: The Webhook node returns the response code and the data output from the last node executed in the workflow.

  • 使用 '响应 Webhook' 节点:Webhook 节点会根据 响应 Webhook 节点中的定义进行响应。

¥Using 'Respond to Webhook' Node: The Webhook node responds as defined in the Respond to Webhook node.

  • 流式响应:启用工作流处理过程中向用户实时传输数据。工作流中需要支持流式的节点(例如,AI 代理 节点)。

¥Streaming response: Enables real-time data streaming back to the user as the workflow processes. Requires nodes with streaming support in the workflow (for example, the AI agent node).

响应代码#

¥Response Code

自定义 Webhook 节点成功执行后返回的 HTTP 响应代码。从常用响应代码中选择或创建自定义代码。

¥Customize the HTTP response code that the Webhook node returns upon successful execution. Select from common response codes or create a custom code.

响应数据#

¥Response Data

选择要在响应正文中包含的数据:

¥Choose what data to include in the response body:

  • 所有条目:Webhook 返回数组中最后一个节点的所有条目。

¥All Entries: The Webhook returns all the entries of the last node in an array.

  • 第一条 JSON 数据:Webhook 返回 JSON 对象中最后一个节点第一个条目的 JSON 数据。

¥First Entry JSON: The Webhook returns the JSON data of the first entry of the last node in a JSON object.

  • 第一条二进制数据:Webhook 返回二进制文件中最后一个节点第一个条目的二进制数据。

¥First Entry Binary: The Webhook returns the binary data of the first entry of the last node in a binary file.

  • 无响应体:Webhook 返回时不包含正文。

¥No Response Body: The Webhook returns without a body.

仅适用于“响应 > 当最后一个节点完成时”。

¥Applies only to Respond > When Last Node Finishes.

节点选项#

¥Node options

选择“添加选项”以查看更多配置选项。可用选项取决于你的节点参数。有关可用选项,请参阅表格。

¥Select Add Option to view more configuration options. The available options depend on your node parameters. Refer to the table for option availability.

  • 允许的来源(CORS):设置允许的跨域域名。输入允许跨域非预检请求的 URL 列表(以逗号分隔)。使用 *(默认)允许所有来源。

¥Allowed Origins (CORS): Set the permitted cross-origin domains. Enter a comma-separated list of URLs allowed for cross-origin non-preflight requests. Use * (default) to allow all origins.

  • 二进制属性:启用此设置后,Webhook 节点可以接收二进制数据,例如图片或音频文件。输入要写入接收到的文件数据的二进制属性名称。

¥Binary Property: Enabling this setting allows the Webhook node to receive binary data, such as an image or audio file. Enter the name of the binary property to write the data of the received file to.

  • 忽略机器人:忽略来自链接预览器和网络爬虫等机器人的请求。

¥Ignore Bots: Ignore requests from bots like link previewers and web crawlers.

  • IP 地址白名单:启用此选项可限制谁(或什么)可以调用 Webhook 触发 URL。输入允许的 IP 地址列表(以逗号分隔)。从白名单之外的 IP 地址访问将返回 403 错误。如果留空,所有 IP 地址均可调用 webhook 触发 URL。

¥IP(s) Whitelist: Enable this to limit who (or what) can invoke a Webhook trigger URL. Enter a comma-separated list of allowed IP addresses. Access from IP addresses outside the whitelist throws a 403 error. If left blank, all IP addresses can invoke the webhook trigger URL.

  • 无响应体:启用此选项可阻止 n8n 在响应中发送正文。

¥No Response Body: Enable this to prevent n8n sending a body with the response.

  • 原始数据正文:指定 Webhook 节点将以原始格式(例如 JSON 或 XML)接收数据。

¥Raw Body: Specify that the Webhook node will receive data in a raw format, such as JSON or XML.

  • 响应内容类型:选择 Webhook 正文的格式。

¥Response Content-Type: Choose the format for the webhook body.

  • 响应数据:在响应中发送自定义数据。

¥Response Data: Send custom data with the response.

  • 响应标头:在 Webhook 响应中发送额外的标头。请参阅 MDN Web 文档 | 响应头 了解更多关于响应标头的信息。

¥Response Headers: Send extra headers in the Webhook response. Refer to MDN Web Docs | Response header to learn more about response headers.

  • 属性名称:默认情况下,n8n 返回所有可用数据。你可以选择返回特定的 JSON 键,以便 n8n 返回该值。

¥Property Name: by default, n8n returns all available data. You can choose to return a specific JSON key, so that n8n returns the value.

选项 必填节点配置
允许的来源(CORS) 任何
二进制属性 选项:
HTTP 方法 > POST
HTTP 方法 > PATCH
HTTP 方法 > PUT
忽略机器人: 任何
IP 地址白名单 任何
属性名称 两者:
响应 > 当最后一个节点完成时
响应数据 > 第一个条目 JSON
无响应体 立即响应
原始数据 任何
响应代码 除“响应”> 使用 '响应 Webhook' 节点之外的任何操作
响应内容类型 两者:
响应 > 当最后一个节点完成时
响应数据 > 第一个条目 JSON
响应数据 立即响应
响应标头 任何

n8n 如何保护 HTML 响应#

¥How n8n secures HTML responses

n8n 版本 1.103.0 版本开始,n8n 会自动将 Webhook 的 HTML 响应封装在 <iframe> 标签中。这是一项保护实例用户的安全机制。

¥Starting with n8n version 1.103.0, n8n automatically wraps HTML responses to webhooks in <iframe> tags. This is a security mechanism to protect the instance users.

这具有以下意义:

¥This has the following implications:

  • HTML 在沙盒化的 iframe 中渲染,而不是直接在父文档中渲染。

¥HTML renders in a sandboxed iframe instead of directly in the parent document.

  • 尝试访问顶层窗口或本地存储的 JavaScript 代码将会失败。

¥JavaScript code that attempts to access the top-level window or local storage will fail.

  • 沙盒 iframe 中不提供身份验证标头(例如,基本身份验证)。你需要使用其他方法,例如在 HTML 中嵌入一个短期访问令牌。

¥Authentication headers aren't available in the sandboxed iframe (for example, basic auth). You need to use an alternative approach, like embedding a short-lived access token within the HTML.

  • 相对 URL(例如 <form action="/">)将无法使用。改用绝对 URL。

¥Relative URLs (for example, <form action="/">) won't work. Use absolute URLs instead.

模板和示例#

¥Templates and examples

Template widget placeholder.

常见问题#

¥Common issues

有关常见问题或建议的解决方案,请参阅 常见问题

¥For common questions or issues and suggested solutions, refer to Common issues.