2
votes

I am trying to use Microsoft graph API to retrieve the Profile pic from Azure Active directory.

I have used below URL and I am able to get the response successfully. https://graph.microsoft.com/v1.0/users/[email protected]

With the same code I am getting below JSON error when i use below URL to fetch the profile photo information. URL i used: https://graph.microsoft.com/users/[email protected]/photo/$value

Error JSON i got:

{
  "error": {
    "code": "OrganizationFromTenantGuidNotFound",
    "message": "The tenant for tenant guid '<<My Tenant GUID>>' does not exist.",
    "innerError": {
      "requestId": "a3f7202f-b2c0-47d4-a04d-4b642c6f4188",
      "date": "2019-07-17T06:33:46",
      "request-id": "a3f7202f-b2c0-47d4-a04d-4b642c6f4188"
    }
  }
}

Could any please help me on this. Thank you.

Update: My App permission in the portal My App permission in the portal

2

2 Answers

2
votes

The all available formats of this API are listed on https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#get-the-photo. I doubt there is a format like the one you are referring "https://graph.microsoft.com/microsoft.com/users/[email protected]/photo/$value"

Note: You could use Microsoft Graph API beta version to get user profile picture. Its very simple and straight forward. You could try below API:

https://graph.microsoft.com/beta/users/UserIdOrPrincipalName/photo/$value

See the screen shot below:

enter image description here

Permission Required:

Step: 1

enter image description here

Step: 2

enter image description here

Step: 3

enter image description here For details you could refer this thread

0
votes

This URL(https://developer.microsoft.com/en-us/graph/graph-explorer) helped me to find the exact answer. My issue is due to the tenant I am using, I tried same code in my Prod tenant and everything working good.

API i used is https://graph.microsoft.com/v1.0/users/username/photo/$value. No need to use the beta version. Now V1.0 has profile pic inforamtion of AAD.