DEV Community

Cover image for Get User Properties with Graph API in Power Automate
tahmidsparrow
tahmidsparrow

Posted on • Edited on

Get User Properties with Graph API in Power Automate

In the previous article, “Get User Properties with ‘Get user profile’ action in Power Automate”, we discussed the approach to retrieving user profiles in Microsoft Power Automate using the default action “Get user profile (v2).” Now, we will learn how to retrieve specific details of a user’s profile information using Graph API by filtering with the user’s UPN or other properties. In this process, we need to call an HTTP request via Graph API from inside Power Automate using the “Send an HTTP request” action, which requests a specific endpoint. This action allows us to retrieve user profile information in a JSON object for the specified user. By adding the connector to our flow, configuring it with the necessary details such as the endpoint URL, HTTP method, request headers, and body, and using dynamic content to pass in any required parameters or values, we can easily integrate external systems or services with our Power Automate flow and automate our business processes.

You can easily retrieve the complete user profile with the previous action if you have the user’s email or UPN. However, if you don’t have this information, you can still search for the user using their job title or a unique user code within your organization with the help of Graph API request. This process can be seamless and efficient, allowing you to find and access the user’s profile information quickly and easily.

Create a New Flow

  • To start with, go to this link.

  • To start building your flow, sign in to the Power Automate portal with the appropriate authentication credentials. Once signed in, select the environment where you want to create the flow. If you haven’t created an environment yet, you can refer to this article for instructions on how to do so.

  • Now click on “My flows” in the left navigation menu. This will open a window displaying all your existing flows with detailed information about each of them.

  • Next, select the “New flow” drop-down menu, which will display a list of all the possible flows you can create. For this demonstration, let’s select “Instant cloud flow”.

Figure 1: Power Automate window for new flowFigure 1: Power Automate window for new flow

  • A new window will open with a few actions to take, as shown in figure 2. In position 1, you will need to provide a name for the flow. For this example, here we have used “GetUserProfileDetails”.
  • To choose the trigger of this flow from position 2, you can select according to your requirements. For instance, in this example, “Manually trigger a flow” has been selected for easier testing.
  • Once you have provided the name and selected the trigger option, click on the “Create” button, as shown in position 3, to initially create the flow.

Figure 2: Creating Instant cloud flowFigure 2: Creating Instant cloud flow

With Graph API

  • User details can also be retrieved with the Graph API by using an HTTP Get request. The URI would be:

https://graph.microsoft.com/v1.0/users?$filter=<property> eq '<value>'

  • The endpoint to call a user is “https://graph.microsoft.com/v1.0/users“. However, such a request would give you all the users, which may not be what you want. To retrieve specific users based on a condition, you can use the filter option to filter by User Principal Name or other properties. As shown in the URI above, the property name can be used as “mail”, and the value would be the user’s email or UPN.
  • To call this Graph API from Power Automate, we need an action that sends an HTTP request. While several “Send an HTTP request” actions are available, we must use the one from “Office 365 Groups,” as illustrated in Figure 3.
  • In Figure 3, we can see another “Send an HTTP request” action from “Office 365 Users,” which we should not use for this URI. The reason is that using this action will result in an error, as shown below: “URI path is not a valid Graph endpoint, path is neither absolute nor relative or resource/object is not supported for this connector.”

Figure 3: Selecting Send an HTTP request actionFigure 3: Selecting Send an HTTP request action

  • Select ‘Send an HTTP request’ from Office 365 Groups, as shown in Figure 3, we can add it as a new step in Power Automate, just like in Figure 4.
  • In the URI field, enter the Graph API URI with the mail filter, and select the method as ‘Get’, and the Content-Type as ‘application/json’. Other filter conditions, such as JobTitle eq ‘Manager’, can be used as required, which may retrieve multiple entries.
  • To retrieve specific property of the user, “$select” statement can be used like this way:

https://graph.microsoft.com/v1.0/users? $select= displayName, birthday& $filter= JobTitle eq 'Manager'

Figure 4: Details of Send an HTTP RequestFigure 4: Details of Send an HTTP Request

  • After completing all the above steps, save the flow and run it manually since we have selected the trigger condition as a manual trigger. Before running the flow, it will ask for permission to access the provided connector. If the connector has the required permission, the flow will execute.
  • After successfully running the flow, the API will respond with a JSON object containing all the users who meet the specified criteria. You can extract the required information from the JSON response using an expression. The ‘Properties’ panel will be displayed, as shown in Figure 5. All the retrievable properties are listed and discussed in the ‘User Profile Properties’ section.
  • We can easily extract the required property from the JSON response using various actions provided by the ‘Data Operation’ feature. Additionally, we can use the expression functions provided by Power Automate to write custom expressions

Figure 5: Response of the HTTP RequestFigure 5: Response of the HTTP Request

User Profile Properties

Below are some examples of user properties that can be retrieved using the ‘Get user profile’ action, along with their respective types and details. All of these properties can be added as dynamic content to the subsequent steps in the flow.

Property Type Description

Display Name

String

To create a user, it is mandatory to provide the name which is usually a combination of the first name, middle initial, and last name. This property cannot be cleared during updates, and its maximum length is restricted to 256 characters.

Given Name

String

This property represents the user’s first name, and its length cannot exceed 64 characters.

Surname

String

This property represents the user’s last name, with a maximum length of 64 characters.

Nickname

String

The mail alias for the user. This property must be specified when a user is created. Maximum length is 64 characters.

Birthday

DateTimeOffset

The date of birth of the user.

Business Phones

String collection

This property is a collection of strings that holds the user’s phone numbers, but it only allows setting one number.

Hire Date

DateTimeOffset

The user’s hire date is always expressed in UTC time.

User Type

String

This property classifies user types, such as “Member” and “Guest”.

Mail

String

This property contains the SMTP address for the user, for example, demo@tahmidulabedin.me.

User Principal Name

String

The user principal name (UPN) of the user. The UPN is an Internet-style login name for the user based on the Internet standard RFC 822. By convention, this should map to the user’s email name. The general format is alias@domain, where domain must be present in the tenant’s collection of verified domains. This property is required when a user is created. The verified domains for the tenant can be accessed from the verifiedDomains property of organization.

Conclusion

In conclusion, obtaining a user profile within Power Automate is straightforward using the “Get user profile” action. However, if you don’t have the user’s email or UPN and need to use alternative filters like job title, department, or a unique user code within your organization, you can utilize the ‘Send an HTTP request” action from “Office 365 Groups. Simply provide the appropriate Graph API URI and filter condition, and this will return a JSON response containing all users that match the specified criteria. You can extract the desired information using expressions or actions from the ‘Data Operation’ section. Overall, there are several ways to retrieve user information within Power Automate, providing flexibility and options for different scenarios.

Top comments (2)

Collapse
 
jaloplo profile image
Jaime López

Nice article and nice trick for the action to make the HTTP call.

You missed the link in the first step of the "Create a New Flow" chapter.

Collapse
 
tahmidsparrow profile image
tahmidsparrow

Thank you. :)
Fixed the link. Thanks for noticing.