To make it simpler, I will quote an article from Microsoft website:
Some queries against Microsoft Graph return multiple pages of data either due to server-side paging or due to the use of the $top query parameter to specifically limit the page size in a request. When more than one query request is required to retrieve all the results, Microsoft Graph returns an @odata.nextLink property in the response that contains a URL to the next page of results. More on that here – https://learn.microsoft.com/en-us/graph/paging
The Power Automate workflow below shows how to handle paging and extract all of the data (in my case, the display names of all users).
Important! This example is for Graph API only, any other API might structure data differently. The latter will require some adjustments in the workflow.
1) HTTP action. Peek code:
{ "inputs": { "method": "GET", "uri": "https://graph.microsoft.com/v1.0/users", "queries": { "$top": "4", "$select": "displayName" }, "authentication": { "type": "ActiveDirectoryOAuth", "tenant": "your_tenant_id_here", "audience": "https://graph.microsoft.com/", "clientId": "your_client_id_here", "secret": "your_secret_key_here" } } }
My development tenant has only 17 users, that is why I make it pull 4 users per request. That way I trigger paging. However, Graph API supports up to 999 entries per call before any paging.
2) Select action. From:
body('HTTP_-_Graph_API_-_Get_users')?['value']
Select:
item()?['displayName']
Some people use Parse JSON action before this step, I don’t, I drill down into data as is.
3) Initialize variable action – varAADUsers variable (Array type). Value:
body('Select_columns_-_Get_users')
4) Initialize variable action – varAADUsersNextLink variable (String type). Value:
body('HTTP_-_Graph_API_-_Get_users')?['@odata.nextLink']
5) Condition action – checks if varAADUsersNextLink variable is blank.
Please don’t confuse Null and Blank values. If there is no paging, then varAADUsersNextLink variable in Step 4 will have a blank value, not null.
If the system didn’t return any paging, then the workflow successfully finishes – varAADUsers has all entries in it.
6) Do until action. Edit in advanced formula:
@equals(body('HTTP_-_Graph_API_-_Get_more_users')?['@odata.nextLink'], null)
7) HTTP action. Peek code:
{ "inputs": { "method": "GET", "uri": "@variables('varAADUsersNextLink')", "authentication": { "type": "ActiveDirectoryOAuth", "tenant": "your_tenant_id_here", "audience": "https://graph.microsoft.com/", "clientId": "your_client_id_here", "secret": "your_secret_key_here" } } }
8) Set variable action. Value:
body('HTTP_-_Graph_API_-_Get_more_users')?['@odata.nextLink']
9) Select action. From:
body('HTTP_-_Graph_API_-_Get_more_users')?['value']
Select:
item()?['displayName']
10) Compose action. Inputs:
variables('varAADUsers')
11) Set variable action. Value:
union( outputs('Output_varAADUsers'), body('Select_columns_-_Get_more_users') )
RESULT
varAADUsers now contains the display names of all 17 users:
[ "Adele Vance", "Alex Wilber", "Diego Siciliani", "Grady Archie", "Henrietta Mueller", "Isaiah Langer", "Johanna Lorenz", "Joni Sherman", "Lee Gu", "Lidia Holloway", "Lynne Robbins", "Megan Bowen", "Miriam Graham", "Nestor Wilke", "Patti Fernandez", "Paul Bludov", "Pradeep Gupta" ]