In my last blog post we looked at working with application permissions against Microsoft Graph when we work with Power Automate. In todayās post we will look at taking this further by taking the data we retrieved in a flow with a HTTP step to utilise application permissions against Graph, into a canvas app to present in a visual format. In a post coming soon, we will also look at cases when we might need to make a slightly different call to the API using a method such as POST or DELETE.
Building on an existing flow
So letās start by taking the flow we created yesterday in the following post, and weāll make some changes to it so that we can start to bring the data weāre collecting in the flow into a canvas app.
Iām going to put the flow we created yesterday back into edit mode, and Iāll start by changing the trigger on the flow from āManually trigger a flowā to the Power Apps V2 trigger.
Now Iām going to change my request to graph a bit as in this use case Iād like to demonstrate working with some different data. Iād like to get all of the applications in my Azure AD, listed in a canvas app gallery. Iāll change my request URI toā¦
https://graph.microsoft.com/v1.0/applications
Iām now also going to add the Application.ReadWrite.All application permission to my app registration to allow me to make this request here.
Iām still using the same client ID, tenant ID and client secret on my HTTP request that I configured yesterday as I am still working with the same app registration. If you create a new app registration for this different scenario, youāll need to change the authentication inputs on your HTTP step.
Now Iām going to add one more step, which is a response to an app at the bottom of my flow. Iām adding the āRespond to a PowerApp or flowā step to my flow. In this last step I will add an output parameter which is where Iāll populate some dynamic content to pass data back to my app with.
Learn more about input and output parameters in Power Apps flows here
Iām going to give my output parameter a name of Applications and Iāll set the value with the following expression to get into the value array that will come from the body outputs of my HTTP request.
outputs('HTTP')?['body']?['value']
Now testing my flow I can see that Iām getting the data I want passed into my output parameter ready to be picked up by my canvas app.
Youāll notice here we have an object with a single property which is my array as a single JSON string. Weāll handle making that an array with objects again when we get into Power Apps.
Working with ParseJSON() in Power Apps
Now we need to work on displaying our data in Power Apps. I have more content on this below, but weāll go through it here as well for this scenario.
Moving into Power Apps, Iām going to start by creating a canvas app in the same solution that my flow is in.
Before we get started I need to enable a feature in my app to make this work. Head to settings and enable the feature for ParseJSON function and untyped objects.
Letās start by adding a button to our screen which we will configure to retrieve our applications when it is clicked. We could execute the Power Fx we will write somewhere such as a screenās OnVisible property or even our App OnStart to remove the need for manual interaction to retrieve and display data, but for now I will just use a button.
Iāve added a button to my screen and Iāve set the label to āGet Applicationsā.
I now need to add my flow to my app to be able to call it using Power Fx. Letās head over to the left hand bar in Power Apps and add our flow.
Now I can reference and call my flow in Power Fx within my app. Iām going to go back to my button and set the OnSelect property to the following.
Set(gblApplications, Table(ParseJSON(ApplicationpermissionswithMicrosoftGraph.Run().application)))
Next Iāll add a gallery to my application and set its Items property toā¦
gblApplications
Iāll then select my button to retrieve data which will populate a number of records in my gallery. Iāll now need to do some work to display data in labels though. When working with ParseJSON I wonāt be able to get field suggestions from intellisense so Iāll need to go back to my flow to find the exact field names I need to reference in my gallery.
Iām going to set the main label in my gallery toā¦
ThisItem.Value.displayName
This is going to display the name of my application.
Then Iāll set the next label to the following to display the sign in audience of my application.
ThisItem.Value.signInAudience
Now weāre retrieving data from Microsoft Graph using application permissions and we are displaying it in Power Apps.
Upcoming content
In my upcoming posts weāll look at some different requests we can make towards Microsoft Graph using application permissions and Power Apps. Specifically, we will build on this scenario and look at the ability to delete an application in our gallery with a DELETE request.
If youāre enjoying this content on Microsoft Graph and utilising the wider Microsoft Cloud ecosystem when building on the Power Platform, make sure you subscribe to my blog to get my posts directly in your inbox! š©