John Bartlett
John Bartlett

Reputation: 430

Microsoft Graph API - Expand User Photos

I am currently trying to grab all user information using the Microsoft Graph API and I was wondering if there was a more concise way of also grabbing a users photos to replace what I am currently doing.

I am currently doing the following;

  1. Grab user details by calling https://graph.microsoft.com/beta/users?$expand=manager NOTE: I am using the beta API as I cannot seem to get the manager data back otherwise.

  2. Iterate over users and then for each user call https://graph.microsoft.com/beta/users/{user_id}/photos

  3. For each photo returned I am then;

    1. Calling https://graph.microsoft.com/beta/users/{user_id}/photos/{photo_id} to get the meta data (e.g. id, height and width). NOTE: I have found the height and width on the initial photos are not always correct whereas they are on this call (so I use this one only for the details)
    2. Calling https://graph.microsoft.com/beta/users/{user_id}/photos/{photo_id}/$value to get the image.

This results in lots of individual API calls on top of the users query;

This could quickly get substantial with a large organisation utilizing multiple profile pictures per person for different sizes.

Is there a way of expanding the photo data within the initial users call to avoid having to do all of these additional API calls?

Thanks, John

Upvotes: 2

Views: 1925

Answers (1)

Dan Kershaw - MSFT
Dan Kershaw - MSFT

Reputation: 5838

Couple of things here John.

  1. Calling GET https://graph.microsoft.com/v1.0/me/photos API is basically a way for you to see what photo sizes are available. You can optimize which size you want, based on your experience - for example if it's a mobile device you might select the smallest (or second smallest size). If it's for a desktop device, you might select the largest size. Requesting GET https://graph.microsoft.com/v1.0/me/photo (note the singular) will get the metadata for the largest available photo. The smaller sizes are scaled versions of the largest photo. In some circumstances, only one size is available. Please see details here. So I'm not sure why you need to get every profile photo size (it's the same photo, but different sizes).
  2. You should take a look at batching to make multiple API calls in one round-trip. Please see this batching topic. NOTE: Batching is still in preview, but will GA soon.

Hope this helps,

Upvotes: 2

Related Questions