Share

Get Operation with Pagination – Library Workflow Wrapper

by Mayank Goyal · 10 Apr 2025

Update Updated package v1.1 with a minor change in Get Operation with Pagination workflow – output contentAsString now wrapped inside content key same as Library Get Operation workflow. Just replace the Get Operation with Get Operation with Pagination workflow to enable pagination right in your workflows.

Introduction

Pagination is a common requirement when working with REST APIs, including Aria Automation (vRA) APIs. While vRA’s REST APIs implement pagination in a straightforward way, handling it properly in Aria Orchestrator (vRO) workflows can make your automation more easier to test and care-free as you don’t have to handle the tokens. Many of the times, We just want to use OOB Get Operation workflow instead of implementing a custom script, possibly because it’s either hard to develop in their environment or they don’t want to share their creds – ASAT.

In this blog post, I’ll walk through creating a wrapper workflow that handles pagination for the “Get operation” library workflow in the vRA plugin for vRO.

📙Understanding vRA Pagination

Before we dive into the implementation, let’s understand how vRA handles pagination:

  • vRA APIs typically return paginated results with a default page size
  • The response includes:
    • content: Array of items for the current page
    • totalElements: Total number of items across all pages
    • totalPages: Total number of pages
    • number: Current page index (0-based)
    • size: Number of items per page

🎁Why Create a Wrapper Workflow?

The existing “Get operation” library workflow in the vRA plugin doesn’t automatically handle pagination. By creating a wrapper workflow, we can:

  1. Simplify pagination handling for consumers
  2. Reduce duplicate code across workflows
  3. Provide consistent pagination behavior
  4. Avoid using custom scripts

📄How to use the Wrapper Workflow?

Intentionally, I have kept it the way we would use the library workflow Get Operation. Only difference would be the output string would only contains items and not other metadata details like content section (where single page items resides generally), paging related data, etc.

📦Download package from here.

🎥 Demo

Once you add Get Operation with Paging workflow in your main workflow, simply bind the contentAsString variable to your scriptable task (check demo) and parse the items like this:

JavaScript
//var items = JSON.parse(contentAsString); 
var items = JSON.parse(contentAsString).content; //v1.1 update 
System.log(items.length); //print items count
for (var i in items){
    System.log(JSON.stringify(items[i])); //print all items
}

🤝Conclusion

Creating this pagination wrapper workflow provides a reusable solution that:

  1. Simplifies working with paginated vRA APIs
  2. Reduces boilerplate code in other workflows
  3. Can be extended with additional functionality

The implementation leverages the existing “Get operation” workflow while adding the pagination logic around it. This approach follows the “wrapper” pattern, where we enhance existing functionality without modifying the original code.

By implementing this pattern, you’ll save time on future vRA integrations and ensure consistent handling of paginated results across your vRO workflows.

👉 Let me know if you find any issues. Comment them down and I will try to fix them for you. Happy coding!

Just in case…

If you are looking for a plain script that supports paging without the complications of using workflows, try this.

JavaScript
//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);


Discover more from Cloud Blogger

Subscribe to get the latest posts sent to your email.

You may also like