Skip to main content

variables Scenario 4 — API Pagination with Token and Page Variables

Written by RTILA X Engineering Team

Intermediate ~6 min
Prerequisites: variables/1 variables/2

What You'll Learn

Manipulate lists with push and pop

Real-World Use Case

Collecting URLs during a crawl

LIVE DEMO

API Pagination

Page 3 of 5, reached via the path variable /scenarios/variables/4/3.

11 Lambda K11
12 Mu L12
13 Nu M13
14 Xi N14
15 Omicron O15
Page 3 of 5
EXPECTED OUTPUT

All API Page Data

id name value
1 Alpha A1
2 Beta B2
3 Gamma C3
4 Delta D4
5 Epsilon E5
6 Zeta F6
7 Eta G7
8 Theta H8
9 Iota I9
10 Kappa J10
11 Lambda K11
12 Mu L12
13 Nu M13
14 Xi N14
15 Omicron O15
16 Pi P16
17 Rho Q17
18 Sigma R18
19 Tau S19
20 Upsilon T20
21 Phi U21
22 Chi V22
23 Psi W23
24 Omega X24
25 Lambda2 Y25
RTILA X PROJECT JSON

RTILA X Automation Project

api-pagination-token-page.json
{
  "name": "API_Pagination_Token_And_Page",
  "settings": {
    "urls": [
      "http://localhost:4321/scenarios/variables/4"
    ],
    "variables": [
      {
        "name": "api_token",
        "required": true,
        "value": "demo-token-abc123"
      },
      {
        "name": "page_num",
        "required": true,
        "value": "1"
      }
    ]
  },
  "datasets": {
    "api_page_data": {
      "item_selector": "css=table.api-page-data tbody tr",
      "properties": [
        {
          "name": "id",
          "type": "text",
          "selector": "css=td:nth-child(1)"
        },
        {
          "name": "name",
          "type": "text",
          "selector": "css=td:nth-child(2)"
        },
        {
          "name": "value",
          "type": "text",
          "selector": "css=td:nth-child(3)"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "goto",
      "params": {
        "url": "http://localhost:4321/scenarios/variables/4?token=${api_token}"
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "api_page_data"
      }
    },
    {
      "command": "set_variable",
      "params": {
        "name": "page_num",
        "value": "2"
      }
    },
    {
      "command": "repeat",
      "params": {
        "times": 4,
        "do": [
          {
            "command": "goto",
            "params": {
              "url": "http://localhost:4321/scenarios/variables/4/${page_num}?token=${api_token}"
            }
          },
          {
            "command": "extract_data",
            "params": {
              "dataset": "api_page_data"
            }
          },
          {
            "command": "math_operation",
            "params": {
              "left_operand": "${page_num}",
              "operator": "+",
              "right_operand": "1",
              "output_variable": "page_num"
            }
          }
        ]
      }
    }
  ]
}

This is page 3 of the paginated demo, served as its own pre-rendered HTML page at /scenarios/variables/4/3.

Did you complete this scenario?

Ready to run this automation?

Copy the project JSON above, open RTILA X, create a new project, and paste it.

This scenario covers 1 RTILA X command and is referenced in 2 learning articles.

Continue Learning

Was this helpful?