Use Power Automate Connector Actions directly from Power Apps

Often people create flows to call Microsoft Graph end points or Approval from within Power Apps rather than “Power Automate connector actions” from within Power Apps.

Connectors

Most likely you will know that the Power Platform has connectors and connectors have triggers and actions. Now adding actions to flows is quite easy. But using the actions inside a Power Apps is a bit trickier.

I’m going to start with a simple example. Add the Office 365Users connection to your app and then there is an HTTP action that you can call. You just supply the endpoint, the GET method and the Content Type and …

Connector Actions used within Power Apps
Connector Actions used within Power Apps

With the following code we can collect the profile of the logged in user:

Set(myVar, Office365Users.HttpRequest("https://graph.microsoft.com/v1.0/me","GET","",{ContentType:"application/json"}) );

Now when we preview the myVar variable we will find an untyped object.

Call the Graph API from Power Apps
Call the Graph API from Power Apps

Typecasting the object

In one of my previous posts I mentioned how to type cast data using User Defined Types, however I was getting the following error with that:

Additional fields/columns not allowed in inputs of type record and table
Additional fields/columns not allowed in inputs of type record and table

Converting my data like this simply works. @odata.context in the example below of course has little additional value and could be removed from the example below.

Set(myVar3, { 
                '@odata.context' :  Text(myVar.'@odata.context'),
                displayName: Text(myVar.displayName), 
                givenName: Text(myVar.givenName),
                mail: Text(myVar.mail),
                jobTitle: Text(myVar.jobTitle),
                mobilePhone: Text(myVar.mobilePhone),
                officeLocation: Text(myVar.officeLocation),
                preferredLanguage: Text(myVar.preferredLanguage),
                userPrincipalName: Text(myVar.userPrincipalName),
                id: Text(myVar.id)
            } );

Now how do we figure out the available fields?

There are a few tools that can be used to understand the data that comes back from the end point.

  1. Microsoft documentation for the Graph API
  2. Graph Explorer to test run and then collect the output.
  3. Power Automate. You could run the same action in Power Automate and then copy the details.
  4. Any other tool that can call Graph end points.

Now we can take this further into for example the calendars in Microsoft Graph. For more information about the scopes of the various HTTP request actions please read my post HTTP vs Send HTP request actions.

Type casting Graph API output
Type casting Graph API output

So should we always use the HTTP Request actions?

No! If there are other connector actions available within the connectors that do what you need then you can use any of those as well.

So for example to get the User Profile image (yes I know we can get this form User().Image )

Get my profile photo
Get my profile photo

Any data like for example the given name of the user can be collected very easily. through the MyProfileV2 action.

Use Power Automate Connector Actions directly from Power Apps
Use Power Automate Connector Actions directly from Power Apps 1

Other connectors?

Can I use any connector?

Yes. Just as easy as it is to collect User information, you can also get for example your Emails displayed in your Power App.

Use Power Automate Connector Actions directly from Power Apps
Use Power Automate Connector Actions directly from Power Apps 2

So do we still need Power Automate?

Yes, for some things Power Automate will be useful. For example to schedule a flow that runs daily and all those other back ground processes.

Creating approval directly form Power Apps

Now one of the reasons for using Power Automate is of course using Approvals now we would create an approval step:

Create approvals within Power Apps
Create approvals within Power Apps

This code needs a second look.

The createAnApproval actions expects first a Approval Type (this is a text) and an object with all the properties.

Approvals.CreateAnApproval("BasicAwaitAll", ParseJSON("{ ""title"": ""Test"", ""assignedTo"" :  ""pieter@PieterVeenstraMVP.onmicrosoft.com"" }") )

When we create the step in Power Automate, we will find in the Code view that Power Automate is very helpful.

Use Power Automate Connector Actions directly from Power Apps
Use Power Automate Connector Actions directly from Power Apps 3

Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

3 thoughts on “Use Power Automate Connector Actions directly from Power Apps

  1. Hello Pieter, please try you add businessPhones: [Text], to the type definition udtProfile to avoid the error message.
    Thank you for your very informative blog posts. 👍

  2. I was probably a bit too quick with my suggestion: it only works if no business phone is returned. In all other cases an error message is displayed “JSON parsing error, expected ‘object’ but got ‘string’ ”.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading