Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Graph API - using expand=photo when getting contacts

https://graph.microsoft.com/v1.0/me/contacts/{id}?$expand=photo

Should return a contact object with a field stating whether the contact has a photo or not

This was already kind of discussed here and here and the response was that this is not possible because "photo" has a binary response while the get contact endpoint returns a json.

however with contacts profilePhoto there are two separate endpoints:

GET /me/contacts/{id}/photo/$value

return the photo itself in binary stream

GET /me/contacts/{id}/photo

returns metadata of the contact's photo - this is extremely useful for figuring out if that contact has a photo or not

by the way, supplying the above "$expand" option doesn't fail the API call, it will add the following header to the json response: "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('[email protected]')/contacts(photo())/$entity", however no field is added to the json object that could help us figure out if that contact has a photo or not.

Some Background:

There may be thousands of contacts in the account, if you want to list them all you don't need too many network calls as you can use:

/me/contacts/microsoft.graph.delta

with header: Prefer=odata.maxpagesize=300

but if you want to show photos of those contacts you can't do it for many contacts at once, if you use batches you can do up to 4 contacts at a time, which results in potentially thousands of API calls where most would probably return 404 since the contact doesn't have a photo. Adding the photo existence field using the $expand would solve this and allow us to reduce our API calls dramatically

Another point to make me think this should have been a supported by the API - in the JSON representation of a contact example it ends with:

"photo": { "@odata.type": "microsoft.graph.profilePhoto" }

But when I get contacts from the API this field doesn't exist

like image 320
marmor Avatar asked Sep 19 '25 10:09

marmor


1 Answers

So the unpopular answer is, as of today this is unsupported, you should upvote the feature.

This questions just doesn’t alphabet a good answer, at the moment…

like image 64
Stephan Avatar answered Sep 23 '25 05:09

Stephan