0

First API to call:

https://proto123.hipchat.com/v2/user?auth_token=2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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:

https://proto123.hipchat.com/v2/user/id?auth_token=2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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.

3
  • 1
    Since you've already been so foreseeing as to add Write-Debug statements, why don't you use them to see where the problem is? Commented Feb 8, 2016 at 23:25
  • What does $webResponse look like? Commented Feb 8, 2016 at 23:40
  • @MathiasR.Jessen I've tried using the debug statements but i couldn't find the problem. Is the script right or am I missing anything here? Commented Feb 9, 2016 at 3:26

1 Answer 1

1

Change

foreach ($webResponseID in $webResponse) {
  ...
}

to

foreach ($webResponseID in $webResponse.items) {
  ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you .. That helped.. Can you check the edited script? I need the participant name, id, in diff rows not in the same one. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.