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 会显示此选项的参数。
  2. Next URL 中,使用一个 表达式 来设置 URL。具体使用的表达式取决于你的 API 返回的数据。例如,如果 API 在响应体中包含一个名为 next-page 的参数:

    1
    {{ $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. 分页模式 设置为 在每个请求中更新参数
  2. 类型 设置为 查询
  3. 输入查询参数的名称。这取决于你的 API,通常在其文档中有说明。例如,一些 API 使用名为 page 的查询参数来设置页面。因此,名称应为 page
  4. 将鼠标悬停在 上并开启 表达式
  5. 输入 {{ $pageCount + 1 }}

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

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

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

  1. 将 HTTP 请求方法设置为 POST
  2. 分页模式 设置为 在每个请求中更新参数
  3. 类型 参数中选择 Body
  4. 输入 Name(body 参数的名称)。这取决于你正在使用的 API。page 是一个常用的键名。
  5. 将鼠标悬停在 上并开启 表达式
  6. 输入 {{ $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. 在主节点参数中选择发送查询参数(这是你首次打开节点时看到的参数,而不是选项内的设置)。
  2. 输入查询参数的 名称。这取决于你的 API。例如,许多 API 使用名为 limit 的查询参数来设置页面大小。因此,名称 将是 limit
  3. 中输入你的页面大小。