Powershell script with Invoke-Restmethod ends before getting APIresponse

I have a powershell script which uses Invoke-RestMethod to invoke an API to trigger test execution. The test execution has takes about 3 hours. However, powershell script ends after 1Hr 40 Mins.

The powershell scripts is triggered as part of Jenkins Job.

Invoke-RestMethod is as below.

$result = Invoke-RestMethod -Headers $basic -Uri $URI -Body $Body -Method Post -ContentType “application/x-www-form-urlencoded;charset=UTF-8” -TimeoutSec 600

How to have the powershell script run till Inoke-RestMethod gets a response?

I tried calling the powershell script as part of Start-Process with -Wait parameter but it does not help.

$Outfilename = $Env:Outputfile
$proc = Start-Process powershell -argument “C:\scripts\xxxxexecution.ps1” -wait -PassThru -RedirectStandardOutput “Outputfile.txt”
$proc.WaitForExit();
if ($proc.ExitCode -ne 0) {
Write-Host “$_ exited with status code $($proc.ExitCode)”
Get-Content .\Outputfile.txt
Exit 1
}
else {
Write-Host “$_ exited with status code $($proc.ExitCode)”
Get-Content .\Outputfile.txt
Exit 0
}

Any help will be appreciated.

According to the documentation, TimeOutSec defaults to 0, which is no timeout:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.1

What does the API documentation state for session length? Are you getting an error? You specified it ends at a very specific time, 1 hr 40 minutes, 100 minutes or 6000 seconds. The code you posted has a limit of 600 seconds, which is 10 minutes. If you are specifying 6000, then it will stop at 1hr 40 min, so no TimeOutSec should be provided or use 0.

Thank you Rob Simmers. I have actually given TimeoutSec as 6000. That was the reason why is it stopping after 1 Hr 40 Mins. I have changed the TimeOutSec to 0, it worked fine.

Burning Series