Skip to content

Instantly share code, notes, and snippets.

@imtrinity94
Last active March 27, 2023 08:04
Show Gist options
  • Save imtrinity94/50ca751d67019762875924160a4d739e to your computer and use it in GitHub Desktop.
Save imtrinity94/50ca751d67019762875924160a4d739e to your computer and use it in GitHub Desktop.
How to handle vRA Pagination using vRO Code
//Assumimg vRA 8.x plugin is already installed in vRO
// typeof host = vRA:Host
var restClient = host.createRestClient();
var items = [];
var path = "/deployment/api/deployments"; // or any other API path
var page = 0;
var page_size = 200; // smaller page_size means more pages to parse
var base_path = path + "?$top=" + page_size;
while (true) {
var skipFilter = page * page_size;
System.log(base_path + "&$skip=" + skipFilter);
var request = restClient.createRequest("GET", base_path + "&$skip=" + skipFilter, null);
request.setHeader("Content-Type", "application/json");
var response = restClient.execute(request);
var statusCode = response.statusCode;
System.log("Status code: " + statusCode);
var contentAsString = response.contentAsString;
contentAsString = JSON.parse(contentAsString);
for (var i = 0; i< contentAsString.content.length; i++)
items.push(contentAsString.content[i]);
page++;
if (page >= contentAsString.totalPages) break
};
System.log("Total number of records fetched: "+ items.length);
@imtrinity94
Copy link
Author

Hits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment