Save output of HTTP Response and payload into separate .txt files

Welcome Forums General PowerShell Q&A Save output of HTTP Response and payload into separate .txt files

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

      Hi,

      I'm want to save output in 2 saperate file, one for http response and other one for payload in .txt files. Below is my code I want to have some idea to get output in .txt files

      $Url = " https//...."
      $Body = @{
      Id = " ... ";
      tokenApi = " .... "
      } | ConvertTo-Json
      $Params = @{
      Uri = $Url;
      Method = 'POST';
      Body = $Body;
      ContentType = 'application/json' }
      $Response = Invoke-RestMethod @Params
      $Token = $Response.token
      
      $Url = " https//...."
      $Header = @{
      Authorization = "Bearer $Token"
      }
      $Body = @{
      gatewayId = " ...."
      } | ConvertTo-Json
      $Params = @{
      Uri = $Url;
      Header = $Header;
      Method = 'POST';
      Body = $Body;
      ContentType = 'application/json' }
      $Response = Invoke-RestMethod @Params
      $Response
      

      Thanks in advance.

    • #177052
      Senior Moderator
      Topics: 8
      Replies: 1141
      Points: 3,927
      Helping Hand
      Rank: Community Hero

      You will have to give more info. What is the output of the rest call ? Can you share us a sample output ?
      What do yo mean by payload here ?

      btwn, you don't need to use semicolon at the end of the line, PowerShell doesn't need it to be there 🙂

      • #177130
        Participant
        Topics: 4
        Replies: 2
        Points: 43
        Rank: Member

        After rest call my out put is "status 200" or "failed with 401 ".

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