VMware Cloud Community
pritamdasgupta
Contributor
Contributor

How to get all vRA deployments from all pages using REST API ?

I am trying to use API "/deployment/api/deployments/" in order to get all deployments from vRA. But unfortunately, I am getting only 20 elements out of 276 elements. How can I get all ? 
Is there way to get data from all pages ? I tried to make use of $top=500 and able to get only 200 elements.

Reply
0 Kudos
13 Replies
xian_
Expert
Expert

Try /deployment/api/deployments?size=500

Reply
0 Kudos
pritamdasgupta
Contributor
Contributor

Hi,

I tried but same result, showing only 20 elements.

 

Thanks

Pritam

Reply
0 Kudos
mastefani
Enthusiast
Enthusiast

Did anyone find an answer to this?  I too am getting limited results of 200 (assuming that's a single page of results).  I've tried the ?size=1000 and the ?top=1000 but either way it seems to be limited to 200 results per page with no obvious way to change pages.

Reply
0 Kudos
emacintosh
Hot Shot
Hot Shot

I find the documentation around the vRA 8 API for filtering, pagination, etc. extremely lacking.  There are some examples in the Programming Guide, but no overarching docs that just tell you how to use it in general.

That said, I think maybe the $skip param is needed here.  I don't think you can get them all at once, but I think you can manage to paginate by setting the $top param for the number per page and the $skip param to <page number>*$top

For example, with 100 per page:

Page 0:   /deployment/api/deployments?$top=100&$skip=0

Page 3:   /deployment/api/deployments?$top=100&$skip=300

mastefani
Enthusiast
Enthusiast

Funny, I was just testing out that skip parameter and using that to return pages.  Still kind of frustrating though having to do multiple REST calls and concatenate the data vs just returning all the deployments in one call.  Thanks

Reply
0 Kudos
jonoterholm
Contributor
Contributor

"?size" works for me, but it still caps at 200. Running version 8.8.

Anyone got around this?

StefanSchnell
Enthusiast
Enthusiast

It seems that the return size of REST API calls is generally limited to 200 elements. I tried /deployment/api/resources with the top parameter of 1000 and it delivers 200 elements, not more. It always seems to be a good idea to request the keys totalElements and numberOfElements to detect differences and to iterate at the result.


More interesting information at blog.stschnell.de

Reply
0 Kudos
kphil22
VMware Employee
VMware Employee

Create a count variable equal to 200, then increment it until it equals the total count of all resources.

your uri would be:

fqdnofVRA + /deployment/api/deployments?'$top=200&'$skip=$($count)

that's the gist of what our powershell looks like.

 

Can't claim any credit for this though. Just passing it along in the hopes it helps someone.

 

 

Dave34
Enthusiast
Enthusiast

Have a look at this page

 

http://sixmillionwaysto.com/156-2

RebeccaW
Enthusiast
Enthusiast

The iaas api does not seem to have the same limitation. Downside is /iaas/api/deployments does not have all the same options such as being able to return soft deleted deployments.

Ankush11s
VMware Employee
VMware Employee

Article has script which goes through all the pages and then collect the data from each deployment related to vsphere machine 
https://vmwarecode.com/2022/04/10/vra-cloud-on-prem-how-to-export-managed-machine-using-python-in-cs...

Rynat18
Contributor
Contributor

Hi! If for example you need to use $top=400, but to use it in URL you need to replace $top with %24top=400. Like

https://your.vra.server/iaas/api/tags?%24top=400

Reply
0 Kudos