Get Request in Postman works but not in Powershell Code

m0d3r Source

I am having several issues. When I do a simple Get request in Postman I get the desired results and JSON object. However when I do a request in Powershell my output file is incomplete and not all the data is there. I get no errors when running my Powershell code, just incomplete data.

What am I doing wrong in my Powershell code? Is there any ideas of what I could be doing wrong in general?

$response = Invoke-RestMethod -Uri "$($privateApiUrl)/api/public/v1/students?" -Headers $headers -Method Get -ErrorVariable RestError -ErrorAction SilentlyContinue

if ($RestError)
{
    $HttpStatusCode = $RestError.ErrorRecord.Exception.Response.StatusCode.value__
    $HttpStatusDescription = $RestError.ErrorRecord.Exception.Response.StatusDescription

    Throw "Http Status Code: $($HttpStatusCode) `nHttp Status Description: $($HttpStatusDescription)"
}
else {

    $response | Out-File -FilePath C:\SQL\response3.txt


}
jsonapipostmanpowershell-v5.0

Answers

comments powered by Disqus