Skip to content

分页 HTTP 请求节点#

¥Pagination in the HTTP Request node

HTTP 请求节点支持分页。本页面提供了一些配置示例,包括使用 HTTP 节点变量

¥The HTTP Request node supports pagination. This page provides some example configurations, including using the HTTP node variables.

有关节点的更多信息,请参阅 HTTP 请求

¥Refer to HTTP Request for more information on the node.

API differences

Different APIs implement pagination in different ways. Check the API documentation for the API you're using for details. You need to find out things like:

  • Does the API provide the URL for the next page?
  • Are there API-specific limits on page size or page number?
  • The structure of the data that the API returns.

启用分页#

¥Enable pagination

在“HTTP 请求”节点中,选择“添加选项”>“分页”。

¥In the HTTP Request node, select Add Option > Pagination.

使用响应中的 URL 通过 $response 获取下一页#

¥Use a URL from the response to get the next page using $response

如果 API 在其响应中返回下一页的 URL:

¥If the API returns the URL of the next page in its response:

  1. 将“分页模式”设置为“响应包含下一个 URL”。n8n 会显示此选项的参数。

¥Set Pagination Mode to Response Contains Next URL. n8n displays the parameters for this option. 2. 在“Next URL”中,使用 expression 设置 URL。具体表达式取决于你的 API 返回的数据。例如,如果 API 在响应正文中包含一个名为 next-page 的参数:

¥In Next URL, use an expression to set the URL. The exact expression depends on the data returned by your API. For example, if the API includes a parameter called next-page in the response body: {{ $response.body["next-page"] }}

使用 $pageCount 按页码获取下一页#

¥Get the next page by number using $pageCount

如果你使用的 API 支持按页码定位特定页面:

¥If the API you're using supports targeting a specific page by number:

  1. 将“分页模式”设置为“每次请求更新一个参数”。

¥Set Pagination Mode to Update a Parameter in Each Request. 2. 设置类型为“查询”。

¥Set Type to Query. 3. 输入查询参数的名称。这取决于你的 API,通常会在其文档中进行说明。例如,某些 API 使用名为 page 的查询参数来设置页面。名称为 page

¥Enter the Name of the query parameter. This depends on your API and is usually described in its documentation. For example, some APIs use a query parameter named page to set the page. So Name would be page. 4. 将鼠标悬停在“值”上,然后启用“表达式”。

¥Hover over Value and toggle Expression on. 5. 输入 {{ $pageCount + 1 }}

¥Enter {{ $pageCount + 1 }}

$pageCount 是 HTTP 请求节点已获取的页面数。初始值为零。大多数 API 的分页计数从 1 开始(第一页即为第一页)。这意味着将 +1 添加到 $pageCount 意味着节点在第一次循环中获取第一页,在第二次循环中获取第二页,依此类推。

¥$pageCount is the number of pages the HTTP Request node has fetched. It starts at zero. Most API pagination counts from one (the first page is page one). This means that adding +1 to $pageCount means the node fetches page one on its first loop, page two on its second, and so on.

通过正文参数导航分页#

¥Navigate pagination through body parameters

如果你使用的 API 允许你通过请求体参数进行分页:

¥If the API you're using allows you to paginate through the body parameters:

  1. 将 HTTP 请求方法设置为 POST。

¥Set the HTTP Request Method to POST 2. 将“分页模式”设置为“每次请求更新一个参数”。

¥Set Pagination Mode to Update a Parameter in Each Request. 3. 在“类型”参数中选择“正文”。

¥Select Body in the Type parameter. 4. 输入正文参数的名称。这取决于你使用的 API。page 是一个通用键名。

¥Enter the Name of the body parameter. This depends on the API you're using. page is a common key name. 5. 将鼠标悬停在“值”上,然后启用“表达式”。

¥Hover over Value and toggle Expression on. 6. 输入 {{ $pageCount + 1 }}

¥Enter {{ $pageCount + 1 }}

设置查询中的页面大小#

¥Set the page size in the query

如果你使用的 API 支持在查询中选择页面大小:

¥If the API you're using supports choosing the page size in the query:

  1. 在主节点参数中选择“发送查询参数”(这是你首次打开节点时看到的参数,而不是选项中的设置)。

¥Select Send Query Parameters in main node parameters (this is the parameters you see when you first open the node, not the settings within options). 2. 输入查询参数的名称。这取决于你的 API。例如,许多 API 使用名为 limit 的查询参数来设置页面大小。名称为 limit

¥Enter the Name of the query parameter. This depends on your API. For example, a lot of APIs use a query parameter named limit to set page size. So Name would be limit. 3. 在“值”中,输入你的页面大小。

¥In Value, enter your page size.