Search code examples
microsoft-graph-apionedrive

How can get user's email from onedrive API?


On the document, I just found I can get displayName from

/drive

But no email

enter image description here

If I want to use this API, can I only through Microsoft Graph?


Solution

  • This is available using the Microsoft Graph API , if your app has requested User.Read permissions.

    You can make a request to get the signed in user's email: GET https://graph.microsoft.com/v1.0/me/mail

    Or you can make a request to get a particular user's email, based on a user ID: GET https://graph.microsoft.com/v1.0/users/{userId}/mail

    You can also use the createdByUser and lastModifiedByUser navigation properties on an item to retrieve the email address for the user who created/modified the file.

    To call Microsoft Graph, you need to use the AAD OAuth v2 authorization / token end point. It's different than what you would have been using for OneDrive personal previously, but documented here: https://dev.onedrive.com/auth/graph_oauth.htm