VMware Cloud Community
Panzerbjorn
Contributor
Contributor

How to get all pages from from Cloud vROps with REST API call?

First, apologies if I am not using correct VMware terminology
We have recently moved to VMWare's cloud vROps, and I am now looking at changing my scripts that previously connected to our on-prem SDDCs, to the Cloud vROps.

I can connect fine, and when I send the request `$Result = Invoke-RestMethod -uri "`https://www.mgmt.cloud.vmware.com/vrops-cloud/suite-api/api/resources"` I get the first 1000 results.
With our on-prem systems I could specify getting up to 5000 results, but nvm about that, I'll just make more calls if necessary.
I would then take the $Result.links, and get the next page's reference from there.
In this case, that would be:

 

 

    href                                               rel     name
    ----                                               ---     ----
    /suite-api/api/resources?page=0&pageSize=1000  SELF    current
    /suite-api/api/resources?page=1&pageSize=1000  NEXT    next
    /suite-api/api/resources?page=0&pageSize=1000  RELATED first
    /suite-api/api/resources?page=27&pageSize=1000 RELATED last

 

 

So I can see that there should be 27 pages. If I make a call to `https://www.mgmt.cloud.vmware.com/vrops-cloud/suite-api/api/resources?page=1&pageSize=1000` Then I get the reply:

 

 

    href                                                                     rel      name
    ----                                                                     ---      ----
    /suite-api/api/resources?amp;pageSize=1000&page=1&pageSize=1000  SELF     current
    /suite-api/api/resources?amp;pageSize=1000&page=0&pageSize=1000  PREVIOUS previous
    /suite-api/api/resources?amp;pageSize=1000&page=2&pageSize=1000  NEXT     next
    /suite-api/api/resources?amp;pageSize=1000&page=0&pageSize=1000  RELATED  first
    /suite-api/api/resources?amp;pageSize=1000&page=27&pageSize=1000 RELATED  last

 

 

So, I was hoping someone here might be able to point me in the right direction of how to get the next 26 pages based on the return from my call.
If I do a DO/WHILE loop;

 

 

$Page = 1
DO
{
	Write-Output "Page $($Page)"
	Write-Output "There are $($Resources.count) resources"
	$InvokeRestMethodSplat.uri = $BaseURI + ($Result.links | where {$_.Name -eq "next"}).href
	$Result = Invoke-RestMethod @InvokeRestMethodSplat
	$Resources += $Result.resourceList
	$Page++
}
UNTIL ((($Result.links | where {$_.Name -eq "last"}).href) -eq (($Result.links | where {$_.Name -eq "Current"}).href))

 

 

then it gets to page 56 and finally stops. The results are mostly duplicates, and the last set of links are:

 

 

href                                                                                                                                                                                                                                                                         
----                                                                                                                                                                                                                                                                         
/suite-api/api/resources?amp;pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pag...
/suite-api/api/resources?amp;pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pag...
/suite-api/api/resources?amp;pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pag...
/suite-api/api/resources?amp;pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pageSize=1000&pag...

 

 

If I manually change the page number, like this:

 

 

$InvokeRestMethodSplat = @{
    Method = "GET"
    Uri = $BaseUri + "/suite-api/api/resources?page=27&pageSize=1000"
    Headers = $Headers
    ContentType = $ContentType
}

 

 

I can get through the pages, but obviously, this is not scalable.
So, is there a way I can get vROps to return the number of pages at least?
Or does someone have a smarter way of doing this?

Labels (2)
0 Kudos
2 Replies
Panzerbjorn
Contributor
Contributor

I guess there isn't a way to do this... -__-

0 Kudos
KabirAli82
Expert
Expert

On prem I would just change the pageSize like suite-api/api/blabla&pageSize=5000

I don't know if it work for the cloud version but I would try something like this:

 

https://www.mgmt.cloud.vmware.com/vrops-cloud/suite-api/api/resources&pageSize=5000


See line 82 on:

https://www.kablog.nl/2021/01/20/restart-stopping-objects-in-vrops/


Was I helpful? Give a kudo for appreciation!
Braindumping @ http://kablog.nl/
Tweeting @ https://twitter.com/_Kabir_Ali_