API Response Body : 400 Bed Request

Hi ,

I’m tying to print Json response body with 400 bed request

Here is code:
try { if ($Responses = (Invoke-WebRequest @Param -ErrorAction Stop)){ $StatusCodes = $([int]$Responses.BaseResponse.statusCode)} Write-Host ("State code : " + $StatusCodes) } >> catch [System.Net.WebException] { $StatusCodes = $_.Exception.Response.StatusCode.Value__ ; $Messages = (($_.Exception.response)) ; Write-Host ("State code : " + $StatusCodes) ; Write-Host ("Message: "+ $Messages) }
But i'm just getting status code 400 only, I want to have response body error as well like this
{
"status": "Failed",
"warnings": {
"errorCode": " ",
"errorDesc": " ",
"errors": [
]
}
}

If you format the code a little bit, it will make other folks to read and understand it better. Please use below link for the instructions

https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/