Need some help with http request node pagination using "Max Pages" expression

Describe the problem/error/question

Trying to paginate results of an http request;

The request takes in a “page” query parameter.

The response provides a “totalPages” parameter that holds the value for the “Max pages” I want to paginate.

The structure of this response is as follows;

    "content": [
    "pageable": {
      "sort": {
        "empty": false,
        "sorted": true,
        "unsorted": false
      "offset": 100,
      "pageNumber": 1,
      "pageSize": 100,
      "paged": true,
      "unpaged": false
    "openCount": 199,
    "closedCount": 0,
    "last": true,
    "totalElements": 200,
    "totalPages": 2,
    "size": 100,
    "number": 1,
    "sort": {
      "empty": false,
      "sorted": true,
      "unsorted": false

I have tried to set the Max Pages value to an expression based on the documentation but it always returns [undefined].

I’ve tried it in so many different ways without success;

{{ $response.body["0"].pageable.totalPages }}
{{ $json["0"]["pageable"]["totalPages"] }}
{{ $json["pageable"]["totalPages"] }}
{{ $json.pageable.totalPages }}
{{ $json.totalPages}}
{{ $response.totalPages}}

At this point I am not sure what I am even doing wrong anymore.

What I am surprised by and would be an intuitive feature is that I could drag the “totalPages” parameter from the http requests response into the expression field for “Max Pages”

Please share your workflow

Information on your n8n setup

  • n8n version: 1.2.0
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): desktop app
  • Operating system: Windows 11

It looks like the path you want would be

When you return $response.body do you see anything?
if yes drill down a level from there, probably to [0]

Thanks for the reply Mitch :wink:

I’ve recorded a short video to go over this part in a bit more detail while demonstrating the issue: Loom | Free Screen & Video Recording Software | Loom