Power Automate: results of an HTTP request

Why?

The results of an HTTP request in Power Automate Flows are returned in JSON format so how to read the results and use it in the different possible ways?

What?

This post will provide some useful examples on how to handle the results of an HTTP request.

How?

The starting point is an HTTP request (in this case to SharePoint) where it tries to find documents in a document libary that meet certain conditions:

The Uri to filter on the column PDtype and only select a number of properties to return including the file name (FileRef):

_api/web/lists/getbytitle('@{variables('varDocLibTitle')}')/Items?$Filter=PDtype eq '@{outputs('Compose_-_DocTypeFilterString')}'&$select=ID,PDtype,PDstatus,Created,Modified,FieldValuesAsText/FileRef&$expand=FieldValuesAsText

Use the results to calculate number of files returned

From the results of this request I want to calculate the number of files returned so I use a compose or variable and use this expression:

@{length(body('Send_an_HTTP_request_to_SharePoint_-_GetDocLibItems')?['d']?['results'])}

Notice that the ‘d’ and the ‘results’ can be found back in the body that the request returned showing an hierarchy in the data returned.

Use the results to get a property of each file found

Sending an HTTP request where there could be possible multiple requests, means that an Apply to each control is needed to iterate through the possible results (unless you are sure you need the first or last results of which more info can be found here in a previous post https://knowhere365.space/microsoft-flow-handy-expressions/#GetPropertyArrayItem):

The output expression should look like this:

@body('Send_an_HTTP_request_to_SharePoint_-_GetDocLibItems')?['d']?['results']

The first compose is getting the FileRef property as plain text:

@{items('Apply_to_each_-_FoundDocument')?['FieldValuesAsText']?['FileRef']}

The second compose is extracting the actual document name / file name from the first compose:

@{last(take(split(outputs('Compose_-_DocURL'),'/'),sub(length(split(outputs('Compose_-_DocURL'),'/')),0)))}

The third compose gets one of the properties of the document definied in the Uri request at the top:

@{items('Apply_to_each_-_FoundDocument')?['ID']}

Leave a comment