invoke-restmethod parse result and go to next page for data

Welcome Forums General PowerShell Q&A invoke-restmethod parse result and go to next page for data

Viewing 2 reply threads
  • Author
    • #246678
      Topics: 1
      Replies: 0
      Points: -26
      Rank: Member

      Hi everyone,

      I have a REST API from where I need to get data downloaded, but when I hit api it shows data for one page but there are many pages of data, so overtime I need to edit the query to go to next page.

      below is the sample of result, please note the api only accept maximum 300 records in a single page,

      page_count : 155
      page_number : 1
      page_size : 300

      to get the next page, I have to use ‘&page_number=2’ in the query, below is the sample query

      Invoke-RestMethod ‘’ -Method ‘GET’ -Headers $headers -Body $body

      I would like to automate the query with a loop and I am bit confused how to do that, I was trying to use the ‘For’ loop but the output is jason when I store it I am not getting the data into a good format, could any one help here?


      • This topic was modified 1 month, 3 weeks ago by praji84.
    • #246714
      Topics: 13
      Replies: 40
      Points: 277
      Helping Hand
      Rank: Contributor

      Let me start by promoting a module I wrote that deals with this:
      You’ll want to take a look at the function Get-vROpsResources.

      The returned data should include information on how many pages there are, so my get all the information for all pages.
      Take a look and let us know how you get on.
      (I would have posted some of the code here, but there’s too much and the code just doesn’t reder here for me for some reason).

    • #246774
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      You can do the following:

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