Home Ask Login Register

Developers Planet

Your answer is one click away!

John Miller February 2016

How to display JSON output?

First API to call:


I get the user IDs when I run this URI.

Then I need to execute the next URI for each user ID generated from the previous URI:


Then print the output file to CSV.

How do I Do that?

Please check this script:

$uri = "https://proto123.hipchat.com/v2/user?auth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
try {
  $webResponse = Invoke-RestMethod -uri $uri -ContentType "application/json"
} catch {
  $webResponse = $_.Exception.Response

if ($webResponse) {
  Write-Debug "Output result"

  $webResponseIDList = @() # Defining array for collecting the ID's
  foreach ($webResponseID in $webResponse) {
    $webResponseIDList += [PSCustomObject] @{
      id = $webResponseID.id
    } # End of ID's Array
    $id = $webResponseID.id

    Write-Host "User ID is : $id" + $webResponseIDList `r`n
    $uri = "https://proto123.hipchat.com/v2/user/$id?auth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
    $webResponseID = Invoke-RestMethod -uri $uri -ContentType "application/json"

    Write-Host "User ID are :" + $webResponseID.id `r`n
    Write-Output "User ID are :" + $webResponseID.id `r`n
} else {
  Write-Debug "No results were returned"

I am not getting the output in PowerShell.


Ansgar Wiechers February 2016


foreach ($webResponseID in $webResponse) {


foreach ($webResponseID in $webResponse.items) {

Post Status

Asked in February 2016
Viewed 1,846 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life