User information is retrieved in SharePoint is different from user information retrieved from MS Graph. But to get the information from Graph in SharePoint, we have to retrieve another access token from AAD instead of SharePoint token.
In this post, you gonna see how to retrieve the user information with profile and AD details by using the SharePoint REST API instead of using MS Graph endpoints. I have used two example requests to fetch the user details from SharePoint. One returns the basic user information from SharePoint and the next one returns the user information directly from AAD.
Get Basic User Information
Below is the frequently used SharePoint REST API to fetch the current user and the result is shown in the picture below,
Get User Information from AAD
And next one is the hidden REST API which returns the properties like user id used in the graph, past projects, birth date and so on.. We can use this API to access any user. To get that, just we have to pass the Principal name of the user. Below is the simple example to retrieve the Graph user information based on the user email id,
By using the above script, we no need to retrieve the access token from AAD and this also reduces the request call and time.
Leave a Reply