Accessing User's profile picture using User's email Graph API

Patrick Poynter 25 Reputation points
2024-09-25T10:26:21.17+00:00

Hi,

I am trying to access a users profile picture using graph api using the endpoint https://graph.microsoft.com/v1.0/users/{username}/photos/48x48/$value

However I get the error Exception of:

type 'Microsoft.Fast.Profile.Core.Exception.ImageNotFoundException' was thrown.

If I swap out the email with the user's ID, it fetches it no problem.

I have sufficient permissions to be able to do this so wondering what I am doing wrong?

Thanks

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rohit Raghuwanshi - MSFT 625 Reputation points Microsoft External Staff
    2024-09-25T12:03:24.5333333+00:00

    Hi Patrick Poynter,

    Thank you for reaching out, Microsoft!

    The error you are getting is only returned when the user has not updated profile photo or if user does not exist. Please ensure you are passing correct UPN in URL. Also, for some users email and UPN can be different so please check you are using user's UPN as profilePhoto Doc mentions to use UPN or ID to fetch profile photo. Also please ensure you provide ProfilePhoto.Read.All permission to access photo. Please refer below screenshots:

    1 /user showing users email and UPN are different: User's image

    1. fetching photo with UPN:

    User's image

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.