Thanks for reaching out. It seems you are trying to find the corresponding Entra ID user using Graph API. There are two attributes on the User Resource that you can target. You can use the userPrincipalName or onPremisesSamAccountName (whichever applies to the environment you are using).These properties can be used to query and identify users in Entra ID (formerly Azure AD) using the Microsoft Graph API.
Here are useful documentation links to reference regarding the properties userPrincipalName or onPremisesSamAccountName
https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#properties
Use Graph API to find a User Entity in Entra ID(formerly AzureAD) using the AzureAD\Username account name
I'm working on a desktop application which accesses EntraID via the C# Graph API SDK.
The application monitors logged in users(s) and returns the logged in User account in the form 'AzureAD\UserName'.
As an example, consider logged in user account 'AzureAD\JohnSmith'. What I need to do is find the corresponding 'John Smith' user entity in the connected Entra tenant.
I guess what is needed is a user attribute/property which holds the account name value 'AzureAD\JohnSmith' and use this to query Entra via the Graph API. I've searched the Entra admin centre and cannot find any suitable user attribute/property.
I would be most grateful for any pointers or suggestions.
Thanks
-John
Microsoft Security Microsoft Entra Microsoft Entra ID
2 answers
Sort by: Most helpful
-
Carolyne-3676 296 Reputation points
2025-03-27T05:58:07.1166667+00:00 -
Goutam Pratti 6,170 Reputation points Microsoft External Staff Moderator
2025-03-27T08:17:42.2233333+00:00 Hello @John Knox ,
I Understand you are working on a desktop application which accesses EntraID via the C# Graph API SDK. Where the application monitors logged in users(s) and returns the logged in User account in the form 'AzureAD\UserName'. Where you need a user attribute/property which holds the account name value
'AzureAD\JohnSmith'
and use this to query Entra via the Graph API.It is not possible to retrieve the name value as
'AzureAD\johnSmith'
using the Graph API. However, you can retrieve the user properties through the Graph API, as explained below.You can use the UserPrincipalName (UPN) to identify and retrieve user properties in Entra ID using the Graph API. The UPN is typically formatted as '@domain.com'. For example, if your domain is 'contoso.com', the UPN would be '@contoso.com'.
Once you have the UPN, you can query the Graph API like this:
GET https://graph.microsoft.com/v1.0/users/{userPrincipalName}
Replace
{userPrincipalName}
with the derived UPN. This will return the corresponding user entity user properties.As you can see from the response above, the user properties are being retrieved using the Graph API. If you want to retrieve a specific attribute or property of the user, you can use the
$select
query parameter, as outlined in the documentation.Additionally Custom attributes, such as extension attributes synced from on-premises to Microsoft Entra ID, will not be directly visible in the Entra portal’s user profile UI. To access these attributes, you’ll need to use PowerShell or the Microsoft Graph API.
For Additional information you can follow the document: https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http
Hope this helps. Let me know if you have any additional queries let us Know. Happy to help.
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.