Skip to main content

loops Scenario 4 — Repeat API Call 5 Times

Written by RTILA X Engineering Team

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

What You'll Learn

Repeat an API call until success

Real-World Use Case

Polling an external service for status

LIVE DEMO

API Endpoint Simulator

This demo simulates repeated API calls. Each request returns the same deterministic status response shown below.

{
  "status": "ok",
  "timestamp": "2025-01-15T10:30:00Z",
  "checks": [
    {
      "name": "Home page",
      "status": "ok",
      "latency": 84
    },
    {
      "name": "Products API",
      "status": "ok",
      "latency": 122
    },
    {
      "name": "Database",
      "status": "degraded",
      "latency": 560
    }
  ]
}
IDEndpointMethodStatusLatency
1 /api/status GET 200 142ms
2 /api/status GET 200 138ms
3 /api/status GET 200 151ms
4 /api/status GET 200 145ms
5 /api/status GET 200 149ms
EXPECTED OUTPUT

RTILA X PROJECT JSON

    {
  "name": "Repeat_API_Call_Five_Times",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/loops/4"
    ],
    "headless": false,
    "navigation_timeout": 30000,
    "max_concurrent_workers": 1,
    "humanoidEnabled": true,
    "humanoidSensitivity": "medium"
  },
  "datasets": {},
  "commands": [
    {
      "command": "goto",
      "params": {
        "url": "https://learn.rtila.com/scenarios/loops/4"
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.api-repeat-demo"
      }
    },
    {
      "command": "repeat",
      "params": {
        "times": 5,
        "do": [
          {
            "command": "http_request",
            "params": {
              "url": "https://learn.rtila.com/scenarios/loops/4",
              "method": "GET"
            }
          },
          {
            "command": "wait",
            "params": {
              "timeout": 10000
            }
          }
        ]
      }
    },
    {
      "command": "wait_for_selector",
      "params": {
        "selector": "css=.api-response"
      }
    },
    {
      "command": "extract_data",
      "params": {
        "dataset": "api_responses"
      }
    }
  ]
}
  

RTILA X Concepts

The repeat command runs a block a fixed number of times. Each cycle issues an HTTP request to the endpoint and waits before the next iteration.

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 2 RTILA X commands and is referenced in 2 learning articles.

Continue Learning

Was this helpful?