Welcome › Forums › General PowerShell Q&A › Powershell script with Invoke-Restmethod ends before getting APIresponse
- This topic has 3 replies, 3 voices, and was last updated 2 weeks, 5 days ago by
Participant.
-
AuthorPosts
-
-
December 28, 2020 at 5:04 am #282661
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.
-
This topic was modified 3 weeks ago by
Vivek.
-
This topic was modified 3 weeks ago by
-
December 28, 2020 at 9:33 am #282682
According to the documentation, TimeOutSec defaults to 0, which is no timeout:
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.
-
December 30, 2020 at 3:43 am #283177
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.
-
December 30, 2020 at 3:59 am #283192
-
-
AuthorPosts
- You must be logged in to reply to this topic.