Optisway home
Documentation menu

REST API reference: Pagination

Lists of runs come in pages, newest first. You choose the page size with limit and move to older runs with the before cursor that next already contains.

How pages work

limit sets how many runs a page holds: a whole number from 1 to 50, or 20 when you leave it out. Any other value answers 400 invalid_request.

before is a run id: the page then holds only runs older than that run. next is the ready-made path of the following page, with before set to the last id of this page, or null when this page was not full. A full last page therefore still has a next, and the page behind it is empty.

The paged lists are GET /runs and GET /tests/{id}/runs; GET /projects and GET /tests return every item at once.

Walking every page

Request GET /runs?limit=50, process items, then request the path in next unchanged; it starts with /api/v1, so only put https://optisway.com in front of it. Repeat until next is null. Do not build the cursor yourself: next keeps your filters such as project or status.

List the runs of a test

GET https://optisway.com/api/v1/tests/tst_7k2m9q4xh3vd/runs?limit=2

Returns: An object with items (Run objects) and next (the path of the next page, or null on the last page).

Status: 200 OK

Headers: Content-Type: application/json; charset=utf-8 Cache-Control: no-store

Response body: List the runs of a testJSON
{
  "items": [
    {
      "id": "4821",
      "testId": "318",
      "testName": "Checkout page",
      "testKind": "availability",
      "projectId": "42",
      "projectName": "Acme Shop",
      "status": "failed",
      "trigger": "api",
      "startedAt": "2026-10-19T09:12:01.000Z",
      "finishedAt": "2026-10-19T09:12:03.140Z",
      "durationMs": 2140,
      "summary": "503 Service Unavailable in 184 ms",
      "checks": {
        "total": 3,
        "passed": 2,
        "failed": 1
      },
      "findings": [
        {
          "severity": "fail",
          "code": "status",
          "message": "503 Service Unavailable",
          "target": "https://shop.example.com/",
          "value": 503,
          "unit": "status",
          "ruleId": null
        },
        {
          "severity": "pass",
          "code": "redirect-chain",
          "message": "No redirects",
          "target": "https://shop.example.com/",
          "value": 0,
          "unit": "count",
          "ruleId": null
        },
        {
          "severity": "pass",
          "code": "response-time",
          "message": "184 ms",
          "target": "https://shop.example.com/",
          "value": 184,
          "unit": "ms",
          "ruleId": null
        }
      ],
      "artifacts": {
        "bytes": 48213,
        "video": false,
        "url": "/api/v1/runs/4821/artifacts",
        "filesUrl": "/api/v1/runs/4821/files"
      },
      "artifactError": null,
      "createdAt": "2026-10-19T09:12:00.000Z",
      "links": {
        "self": "/api/v1/runs/4821",
        "test": "/api/v1/tests/318"
      }
    },
    {
      "id": "4790",
      "testId": "318",
      "testName": "Checkout page",
      "testKind": "availability",
      "projectId": "42",
      "projectName": "Acme Shop",
      "status": "failed",
      "trigger": "schedule",
      "startedAt": "2026-10-18T09:12:02.000Z",
      "finishedAt": "2026-10-18T09:12:12.310Z",
      "durationMs": 10310,
      "summary": "The page could not be loaded: No response within 10 s.",
      "checks": {
        "total": 1,
        "passed": 0,
        "failed": 1
      },
      "findings": [
        {
          "severity": "fail",
          "code": "fetch-error",
          "message": "No response within 10 s.",
          "target": "https://shop.example.com/",
          "value": null,
          "unit": null,
          "ruleId": null
        }
      ],
      "artifacts": {
        "bytes": 41877,
        "video": false,
        "url": "/api/v1/runs/4790/artifacts",
        "filesUrl": "/api/v1/runs/4790/files"
      },
      "artifactError": null,
      "createdAt": "2026-10-18T09:12:00.000Z",
      "links": {
        "self": "/api/v1/runs/4790",
        "test": "/api/v1/tests/318"
      }
    }
  ],
  "next": "/api/v1/tests/tst_7k2m9q4xh3vd/runs?limit=2&before=4790"
}

List the failed runs of a project

Lists the failed runs of one project and prints each test name, when it finished and its summary.

#!/usr/bin/env bash
# Print the failed runs of project 42, newest first, following next until null. Needs curl 7.76+ and jq.
set -euo pipefail
origin="https://optisway.com"
auth="Authorization: Bearer $OPTISWAY_API_KEY"
fail() { echo "$1" | jq -r '"\(.error): \(.message)"' >&2; exit 1; }

path="/api/v1/runs?project=42&status=failed&limit=50"
while [ -n "$path" ]; do
  page=$(curl --fail-with-body -sS "$origin$path" -H "$auth") || fail "$page"
  echo "$page" | jq -r '.items[] | "\(.testName)  \(.finishedAt)  \(.summary // "")"'
  path=$(echo "$page" | jq -r '.next // empty')
done
// Node.js 18+: save as list-failures.mjs and run `node list-failures.mjs`
const origin = "https://optisway.com";
const headers = { Authorization: `Bearer ${process.env.OPTISWAY_API_KEY}` };

// `next` is the same path with before=<last id>, or null on the last page.
let path = "/api/v1/runs?project=42&status=failed&limit=50";
while (path) {
  const response = await fetch(origin + path, { headers });
  const page = await response.json();
  if (!response.ok) {
    console.error(`${response.status} ${page.error}: ${page.message}`);
    process.exit(1);
  }
  for (const run of page.items) console.log(run.testName, run.finishedAt, run.summary);
  path = page.next;
}
# pip install requests
import os
import sys

import requests

ORIGIN = "https://optisway.com"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['OPTISWAY_API_KEY']}"

# "next" is the same path with before=<last id>, or None on the last page.
path = "/api/v1/runs?project=42&status=failed&limit=50"
while path:
    response = session.get(ORIGIN + path, timeout=30)
    page = response.json()
    if not response.ok:
        print(f"{response.status_code} {page['error']}: {page['message']}", file=sys.stderr)
        sys.exit(1)
    for run in page["items"]:
        print(run["testName"], run["finishedAt"], run["summary"], sep="  ")
    path = page["next"]
require "json"
require "net/http"
require "uri"

ORIGIN = "https://optisway.com"
KEY = ENV.fetch("OPTISWAY_API_KEY")

# "next" is the same path with before=<last id>, or nil on the last page.
path = "/api/v1/runs?project=42&status=failed&limit=50"
while path
  uri = URI(ORIGIN + path)
  request = Net::HTTP::Get.new(uri)
  request["Authorization"] = "Bearer #{KEY}"
  response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
  page = JSON.parse(response.body)
  unless response.is_a?(Net::HTTPSuccess)
    warn "#{response.code} #{page["error"]}: #{page["message"]}"
    exit 1
  end
  page["items"].each do |run|
    puts [run["testName"], run["finishedAt"], run["summary"]].join("  ")
  end
  path = page["next"]
end
<?php
const ORIGIN = "https://optisway.com";

// "next" is the same path with before=<last id>, or null on the last page.
$path = "/api/v1/runs?project=42&status=failed&limit=50";
while ($path !== null) {
  $curl = curl_init(ORIGIN . $path);
  curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("OPTISWAY_API_KEY")],
  ]);
  $page = json_decode((string) curl_exec($curl), true);
  $status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
  if ($status < 200 || $status >= 300) {
    fwrite(STDERR, "$status " . ($page["error"] ?? "request_failed") . ": "
      . ($page["message"] ?? curl_error($curl)) . "\n");
    exit(1);
  }
  foreach ($page["items"] as $run) {
    echo $run["testName"], "  ", $run["finishedAt"], "  ", $run["summary"], "\n";
  }
  $path = $page["next"];
}
// Java 11+: save as Main.java and run `java Main.java`
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  static final String ORIGIN = "https://optisway.com";

  public static void main(String[] args) throws Exception {
    HttpClient client = HttpClient.newHttpClient();
    // "next" is the same path with before=<last id>, or null on the last page.
    String path = "/api/v1/runs?project=42&status=failed&limit=50";
    while (path != null) {
      HttpRequest request = HttpRequest.newBuilder(URI.create(ORIGIN + path))
          .header("Authorization", "Bearer " + System.getenv("OPTISWAY_API_KEY"))
          .build();
      HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
      String page = response.body();
      if (response.statusCode() >= 300) {
        System.err.println(response.statusCode() + " " + field(page, "error") + ": "
            + field(page, "message"));
        System.exit(1);
      }
      // Run fields come in a fixed order (testName before finishedAt and summary); a JSON library such as
      // Jackson or Gson reads them properly.
      Matcher names = Pattern.compile("\"testName\"\\s*:").matcher(page);
      while (names.find()) {
        String run = page.substring(names.start());
        System.out.println(field(run, "testName") + "  " + field(run, "finishedAt") + "  "
            + field(run, "summary"));
      }
      path = field(page.substring(page.lastIndexOf("\"next\"")), "next");
    }
  }

  /** The first string value of a JSON key (dependency-free; Jackson or Gson parse JSON properly). */
  static String field(String json, String key) {
    Matcher match = Pattern.compile("\"" + key + "\"\\s*:\\s*(?:\"((?:[^\"\\\\]|\\\\.)*)\"|null)")
        .matcher(json);
    return match.find() ? match.group(1) : null;
  }
}
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

const origin = "https://optisway.com"

type page struct {
	Items []struct {
		TestName   string `json:"testName"`
		FinishedAt string `json:"finishedAt"`
		Summary    string `json:"summary"`
	} `json:"items"`
	Next    *string `json:"next"`
	Error   string  `json:"error"`
	Message string  `json:"message"`
}

func main() {
	// next is the same path with before=<last id>, or null on the last page.
	path := "/api/v1/runs?project=42&status=failed&limit=50"
	for path != "" {
		req, err := http.NewRequest(http.MethodGet, origin+path, nil)
		if err != nil {
			panic(err)
		}
		req.Header.Set("Authorization", "Bearer "+os.Getenv("OPTISWAY_API_KEY"))
		resp, err := http.DefaultClient.Do(req)
		if err != nil {
			panic(err)
		}
		var p page
		err = json.NewDecoder(resp.Body).Decode(&p)
		resp.Body.Close()
		if err != nil {
			panic(err)
		}
		if resp.StatusCode >= 300 {
			fmt.Fprintf(os.Stderr, "%d %s: %s\n", resp.StatusCode, p.Error, p.Message)
			os.Exit(1)
		}
		for _, run := range p.Items {
			fmt.Println(run.TestName, run.FinishedAt, run.Summary)
		}
		path = ""
		if p.Next != nil {
			path = *p.Next
		}
	}
}
// .NET 8: `dotnet new console`, replace Program.cs with this file, then `dotnet run`
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;

const string Origin = "https://optisway.com";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
  new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("OPTISWAY_API_KEY"));

// "next" is the same path with before=<last id>, or null on the last page.
string? path = "/api/v1/runs?project=42&status=failed&limit=50";
while (path is not null)
{
  using var response = await client.GetAsync(Origin + path);
  var page = await response.Content.ReadFromJsonAsync<JsonElement>();
  if (!response.IsSuccessStatusCode)
  {
    var error = page.GetProperty("error");
    var message = page.GetProperty("message");
    Console.Error.WriteLine($"{(int)response.StatusCode} {error}: {message}");
    return 1;
  }
  foreach (var run in page.GetProperty("items").EnumerateArray())
  {
    Console.WriteLine(string.Join("  ",
      run.GetProperty("testName"), run.GetProperty("finishedAt"), run.GetProperty("summary")));
  }
  path = page.GetProperty("next").GetString();
}
return 0;