API Response Body : 400 Bed Request

Welcome Forums General PowerShell Q&A API Response Body : 400 Bed Request

Viewing 1 reply thread
  • Author
    Posts
    • #187693
      Participant
      Topics: 4
      Replies: 2
      Points: 43
      Rank: Member

      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": [
              ]
          }
      }
    • #187726
      Senior Moderator
      Topics: 8
      Replies: 1141
      Points: 3,927
      Helping Hand
      Rank: Community Hero

      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/

Viewing 1 reply thread
  • You must be logged in to reply to this topic.