print content
To print the full content data from your Invoke-WebRequest in PowerShell, you need to access and output the Content property of the response object. Below is the adjusted PowerShell code to do this:
PowerShell Code to Print Full Content:
powershell# Send the POST request $response = Invoke-WebRequest -Method POST -Headers @{'x-snow-auth' = 'c8c135a0-05fc-4d2a-8f23-af7f24d66a9c'} -Body "{}" -Uri "https://dev-api.cmnow-dev.ubsdev.net/query?collection=sc_req_item" # Print the entire content of the response Write-Output "Status Code: $($response.StatusCode)" Write-Output "Status Description: $($response.StatusDescription)" Write-Output "Full Response Content:" Write-Output $response.Content
Explanation:
Invoke-WebRequest:
- Sends the POST request to the API with the appropriate
HeadersandBody. $responsestores the result, which includes properties likeStatusCode,StatusDescription,Content, etc.
- Sends the POST request to the API with the appropriate
Content Output:
$response.Contentholds the body of the response (theContentfield), which is typically the JSON or text data returned from the API. This command will print the complete response.
Optional: Parsing the JSON Response
If the response content is in JSON format, and you want to manipulate the data, you can convert it to a PowerShell object and then print specific fields or the entire object.
powershell# Convert the JSON response content to a PowerShell object $jsonResponse = $response.Content | ConvertFrom-Json # Print the parsed JSON content Write-Output $jsonResponse # Example: Access specific fields from the JSON response Write-Output "RITM Number: $($jsonResponse.results[0].number)" Write-Output "REQ Number: $($jsonResponse.results[0].request.display_value)"
Notes:
- If the
Contentcontains large JSON data, it may be truncated in the console. TheConvertFrom-Jsonmethod will allow you to work with it as a structured PowerShell object. - Ensure that the token and URL are correctly formatted and updated for your use case.
Let me know if you need further assistance!
No comments