Please help with script :(

Hi all,
Glad to finally be here. We have the following API problem(ofc beautified) :smiley:
Post asset creates an asset, let us assume the following:

“id”: “51fc4807-d3ed-4b6e-b1f8-ee3eb2e18a96”,
“name”: “Tolik87”,
“description”: “APIDescription”,
“status”: “DAMNED”,

and after that another POST that changes the status of the asset to NOT-DAMNED (it is a job that takes around 3 mins). I want to be able to poll it for when the status becomes NOT-DAMNED, so hitting the API every 30 sec to check if the status is NOT-DAMNED
This should do the trick:
const response = pm.response.json();

if (response.status !== “NOT-DAMNED”) {
setTimeout(() => {}, 30000)
postman.setNextRequest(pm.info.requestId)
}

However I am looking for something to break my loop if it never becomes “NOT-DAMNED”. Anyone can help with that. Tried to save counter in an environment variable but maybe am too stupid to write that script by myself :frowning:

setTimeout(() => {}, 30000)
const response = pm.response.json()
if (!pm.environment.has(“counter”)) {
console.log(“set counter to 0”);
pm.environment.set(“counter”, 0);
}

let currentCount = parseInt(pm.environment.get(“counter”));
console.log(currentCount)

if (currentCount < 10) {
if (response.status === “NOT-DAMNED”) {
postman.setNextRequest(“Next Request”);
}
currentCount++;
pm.environment.set(“counter”, currentCount);
postman.setNextRequest(pm.info.requestId);
}

I came till here but that does not work properly. Added setTimeOut and now when I log count, it stays the same :frowning: