Thursday, November 4, 2021

Logic App Http pagination deeper look, build custom paging wrapper without loop

Introduction 

In this article I will talk how the Http action is doing the pagination on the json response.

there is some requirement to the http end point to be considered as valid pagination 

the response needs to be json

the response needs to have array named value and attribute named nextLink

Like the below diagram

Mohammed_Barqawi_0-1635756565970.png

The http action will check if the nextLink is exist and then make Get request to it 

It will stopped when there is no nextLink attribute in the response 

 

Note

The http method for the nextLink  will be always Get regardless of the http action.

 

Building the Wrapper for ResourceGraph Rest 

The problem 

You want to call https://management.azure.com/providers/Microsoft.ResourceGraph/resources

As in the documentation Resources - Resources - REST API (Azure Azure Resource Graph) | Microsoft Docs

 

It has unique way to handle paging, first the json structure is not as recommended by the standard http pagination also there is something called $skipToken that also need to be passed in the next call.

 

The solution

I have built wrapper logic app that will action as proxy and convert the ResourceGraph response to paging enabled response 

 

Mohammed_Barqawi_1-1635756719608.png

In your business logic app instead of calling the ResourceGraph Endpoint you will call the wrapper logic app 

 

Mohammed_Barqawi_0-1636001275717.png

 

By adopting the wrapper concept, you will avoid implementing the until loop pattern since you will utilize the built-in pagination inside the Http action  

 

How the wrapper is working 




Mohammed_Barqawi_0-1635847776684.png

 

 



Mohammed_Barqawi_3-1635756850874.png

 



1

Initialize the next Link variable by getting the value from triggerOutputs()['queries']?['nextLink']

Because it will come in the query string 

2

Initialize the request body option

This variable either has the Skiptoken or empty 

Sample value when it is not empty 

  "options": {

 "$skipToken" :"abc="   

  },


 

 

Mohammed_Barqawi_4-1635756927394.png

 

3

Creat the Http request that conset of the option (if it exist ) and the query 

4

Sent the request to the http end poit for the ResourceGraph 

 

Mohammed_Barqawi_5-1635756968811.png

 

5

Map the response to the standard pagination format 

And add the next Link attribute in case this is not the last request 


Note that I have a variable that hold the wrapper logic app url so I can build the next link 

 

 

How to use the solution 


Click on the button below to deploy the Logic app to your subscription  

 

Sample logic app templates in GitHub

Deploy to Azure: 

Mohammed_Barqawi_6-1635757172439.png

 

 

Cange the parameters

URL and Query

Posted at https://sl.advdat.com/2ZRlqb6