Consolidate REST API resultset object

Welcome Forums General PowerShell Q&A Consolidate REST API resultset object

Viewing 2 reply threads
  • Author
    Posts
    • #237010
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      I have 5 rest method result set stored in separate object as call required separate API keys.

      $apiKey1 = “SomeKey”
      $apiKey2 = “SomeKey”
      $resource = “http://localhost/api/books”
      $List1=Invoke-RestMethod -Method Get -Uri $resource -Header @{ “X-ApiKey” = $apiKey1 }
      $List2=Invoke-RestMethod -Method Get -Uri $resource -Header @{ “X-ApiKey” = $apiKey2 }

      $List1, $List2.. have same pattern data in json, how to consolidate in single object say $AllResults?

    • #237052
      Participant
      Topics: 7
      Replies: 557
      Points: 2,121
      Helping Hand
      Rank: Community Hero

      Take a look at this example using hashtables and a lookup table. I’ll assume there is one property that is unique and shared between the datasets. This is what we will use as the lookup key. This is just to show you an example one way you can do this. If you have more properties than you want to type out, I’m sure there’s an easy way to walk through each property of each list and either create that property or add to it.

      I hope this helps.

    • #239078
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      Thank you. it helped.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.