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

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
6 days, 14 hours ago.

  • Author
    Posts
  • #176986

    Participant
    Topics: 1
    Replies: 1
    Points: 19
    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: 1041
    Points: 3,439
    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: 1
      Replies: 1
      Points: 19
      Rank: Member

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

You must be logged in to reply to this topic.