Help with writing a loop in postman tests

I have a request (you can use it):

Please help in any way you can

Try this code

pm.environment.set("cursor", "0");

function getNextPage() {
  let cursor = pm.environment.get("cursor");
  pm.sendRequest({
    url: "https://eu-api.backendless.com/1877CC4D-B4EA-4E2D-FFCB-78A7EDACDE00/ACA31220-F45A-474C-94E0-AB0700926637/hive/Management/list/keys?filterPattern=*&pageSize=5&cursor=" + cursor,
    method: "GET",
    header: {
      "Content-Type": "application/json"
    }
  }, function(err, res) {
    let jsonResponse = res.json();
    if (jsonResponse.cursor === "0") {
      // Stop looping if cursor is 0
      console.log("Reached end of results");
    } else {
      // Update cursor and continue looping
      console.log("Current cursor: " + jsonResponse.cursor);
      pm.environment.set("cursor", jsonResponse.cursor);
      getNextPage();
    }
  });
}
getNextPage();

1 Like