I am trying to invoke 2 rest method and executing the 2nd one in loop as shown in below code.
$resultIdRes = (Invoke-RestMethod -Uri "https://neoload-api.saas.neotys.com/v3/workspaces/tests/abcdefgh/start?testResultName=ADOTest6" -Method Post -Headers @{ accountToken = "123456789"}).resultId
Write-Host "Response of Neoload Run API $resultIdRes "
$url = "https://neoload-api.saas.neotys.com/v3/workspaces/abchdsefg/test-results/$resultIdRes/logs"
$expvalue = "Exit with status"
Write-Host "result url $url"
$maxAttempts = 15
$retryIntervalsSeconds = 60
$currentAttempt =1
while ($currentAttempt -le $maxAttempts) {
Write-Host "Log $currentAttempt.."
$response = Invoke-RestMethod -Uri $url -Method Get -Headers @{ accountToken = "123456789"}
Write-Host "$response"
if ($response -match $expvalue){
Write-Host "Test is Completed"
break
}
Start-Sleep -Seconds $retryIntervalsSeconds
$currentAttempt++
}
The code is failing at the 2nd Invoke Rest in the while loop, below is the output
Response of Neoload Run API 938c1a85
result url https://neoload-api.saas.neotys.com/v3/workspaces/abchdsefg/test-results/938c1a85/logs
Log 1..
Invoke-RestMethod : {
"code" : 201,
"message" : "Test result not found."
}
Log 2..
Log 3..
It goes to 2nd iteration waits for 60 seconds and 3rd and so on. Also I am not able to see the write host output in the while loop. Requesting for a help