{
  "name": "ezGPT - API pagination demo",
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "nodes": [
    {
      "id": "dca7b911-1524-4c39-8b02-451361b29e47",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "parameters": {},
      "position": [
        0,
        0
      ]
    },
    {
      "id": "012138f6-ad1d-4769-b0a1-646ed8d28448",
      "name": "Fetch Pages",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "parameters": {
        "url": "http://host.docker.internal:18112/orders",
        "options": {
          "timeout": 3000,
          "response": {
            "response": {
              "responseFormat": "json",
              "neverError": false,
              "fullResponse": false
            }
          },
          "pagination": {
            "pagination": {
              "paginationMode": "updateAParameterInEachRequest",
              "parameters": {
                "parameters": [
                  {
                    "type": "qs",
                    "name": "page",
                    "value": "={{ $pageCount + 1 }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ $response.body.next_page === null }}",
              "limitPagesFetched": true,
              "maxRequests": 10,
              "requestInterval": 100
            }
          }
        }
      },
      "position": [
        220,
        0
      ]
    },
    {
      "id": "90485e48-6428-448b-8736-2f48da9bbeb3",
      "name": "Collection Complete",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "20e67d77-3abc-4951-a1ed-d0849ab7beb9",
              "leftValue": "={{ $input.all().at(-1).json.next_page === null }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "position": [
        440,
        0
      ]
    },
    {
      "id": "e9aeabcc-0905-459c-9c99-7ffaa5aa19d3",
      "name": "Split Orders",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "parameters": {
        "fieldToSplitOut": "orders",
        "include": "noOtherFields",
        "options": {}
      },
      "position": [
        660,
        -100
      ]
    },
    {
      "id": "7024ab33-735b-48b3-b9c4-eaef65f1215c",
      "name": "Ready Orders",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "31558527-1878-4a65-9b63-de517c7a6e5d",
              "name": "order_id",
              "type": "string",
              "value": "={{ $json.order_id }}"
            },
            {
              "id": "3a99f524-54dc-4906-a734-6e738b0d74bb",
              "name": "amount",
              "type": "number",
              "value": "={{ $json.amount }}"
            },
            {
              "id": "b924eac4-551b-4af5-be4a-ea31d0855ae3",
              "name": "status",
              "type": "string",
              "value": "ready"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "position": [
        880,
        -100
      ]
    },
    {
      "id": "9926885d-7796-411c-8b3c-fb11b8b7185f",
      "name": "Incomplete Fetch",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9d351369-1fe8-48d7-8e9d-d7c43942671f",
              "name": "status",
              "type": "string",
              "value": "needs_review"
            },
            {
              "id": "8503fefd-ce47-4ace-bd3e-fdd61a5bc91f",
              "name": "reason",
              "type": "string",
              "value": "last_page_not_confirmed"
            },
            {
              "id": "386dabd0-7de7-475e-8e96-5b717e9a285b",
              "name": "page",
              "type": "number",
              "value": "={{ $json.page }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "position": [
        660,
        160
      ]
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Fetch Pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Pages": {
      "main": [
        [
          {
            "node": "Collection Complete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collection Complete": {
      "main": [
        [
          {
            "node": "Split Orders",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Incomplete Fetch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Orders": {
      "main": [
        [
          {
            "node": "Ready Orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
