How To Handle Pagination In Rest API v2 | Nutanix Community
Skip to main content

I struggle to find info on the topic in Nutanix docs,

I try to understand how to handle pagination when performing REST API request via the v2 API to retrieve all hosts I have in the cluster.

when I make the request I get the metadata section with the following data:

"metadata": {
    "grand_total_entities": ,
    "total_entities": ,
    "filter_criteria": "",
    "sort_criteria": "",
    "page": ,
    "count": ,
    "start_index": ,
    "end_index": 
  }

when i make a request i see that i can specify two fields that relate to pagination 

“page number”

“count”

its not clear how to handle pagination,

if somebody have some code sample it will be great !

Hi,

I think API v2 GET /hosts pagination can handles with “count” and “page” query parameters.


I have jq installed on Linux for a simple example.
It's a 3-host small lab, and NTNX-xxxxxxxx-A is AHV host name.

Linux$ curl -ks -u $CRED "https://$PRISM:9440/PrismGateway/services/rest/v2.0/hosts" | 
jq -r '.entitiesr].name, .metadata'
NTNX-1345a952-A
NTNX-0a648466-A
NTNX-739ee780-A
{
"grand_total_entities": 3,
"total_entities": 3,
"filter_criteria": "",
"sort_criteria": "",
"page": 1,
"count": 3,
"start_index": 1,
"end_index": 3
}

 

1 host per page by “?count=1&page=1” query parameters. Then page 1 is displayed.

Linux$ curl -ks -u $CRED "https://$PRISM:9440/PrismGateway/services/rest/v2.0/hosts?count=1&page=1" | jq -r '.entities|].name, .metadata'
NTNX-1345a952-A
{
"grand_total_entities": 3,
"total_entities": 3,
"filter_criteria": "",
"sort_criteria": "",
"page": 1,
"count": 1,
"start_index": 1,
"end_index": 1
}

 

By setting to “page=3”, the host on the 3rd page is displayed.

Linux$ curl -ks -u $CRED "https://$PRISM:9440/PrismGateway/services/rest/v2.0/hosts?count=1&page=3" | jq -r '.entitiese].name, .metadata'
NTNX-739ee780-A
{
"grand_total_entities": 3,
"total_entities": 3,
"filter_criteria": "",
"sort_criteria": "",
"page": 3,
"count": 1,
"start_index": 3,
"end_index": 3
}

 

The API reference can be found in Prism's API Explorer, but explanation may be insufficient...

https://$PRISM:9440/api/nutanix/v2/api_explorer/


Thanks @go.watanabe03-72705 !

 

@dragon222 - Does the code sample from Go Watanabe above accomplish what you’re looking for?  Please advise, thanks!


Reply