Microsoft Graph – Frequently used Graph API Queries for User – Discussing User object / User Resource Type – Part 2

.MS Graph Permissions
MS Graph Permissions

Hi All,

Greetings for the day!!!

As we are compiling frequently used Microsoft Graph APIs.

In last article we discussed – listing all queries related to users count and users listing. All these queries are “Get” – Microsoft Graph – Frequently used Graph API Queries for Users – Part 1

In this series of articles today we are listing important queries related to only user object. All these queries are “Get“. There are many but here tried to have few.

Also explore different parameters to Graph queries like – Select

  • Microsoft Graph enables us full control over the lifecycle of users in Microsoft 365 including creating, updating, and deleting users and to listing users in the organization

Prerequisites

Bit about User object / User resource type

  • Represents an Azure Active Directory (Azure AD) user account
  • Inherits from directoryObject.

API Permission required for getting user details

fig : Microsoft Graph – API permissions required to execute the user counts and user queries
fig : Microsoft Graph – API permissions required to execute the user counts and user queries

Permission typePermissions (from least to most privileged)
Delegated (work or school account)User.Read, Directory.Read.All
Delegated (personal Microsoft account)User.Read
ApplicationUser.Read.All, Directory.Read.All
Table : Microsoft Graph – Permission Types and required permissions for getting data for User object

  • The User.Read permission allows the app to read the profile, and discover relationships such as the group membership, reports and manager of the signed-in user only

Get current signed in user details

  • Method : GET
https://graph.microsoft.com/v1.0/me

fig : Microsoft Graph – Graph Explorer – Graph API for getting properties of current signed in user

Details :

  • By default this API returns only default set of following properties
    • businessPhones
    • displayName
    • givenName
    • jobTitle
    • mail
    • mobilePhone
    • officeLocation
    • preferredLanguage
    • surname
    • userPrincipalName
  • We will use $select to get the other properties and relationships for the user object.
  • Following properties are returned only on $select
accountEnabledageGroupassignedLicensescompanyName
assignedPlansbirthdaycityconsentProvidedForMinor
countrycreatedDateTimecreationTypedeletedDateTime
departmentemployeeHireDateemployeeIdemployeeOrgData
aboutMeemployeeTypeexternalUserStateexternalUserStateChangeDateTime
faxNumberhireDateidentitiesimAddresses
interestslastPasswordChangeDateTimelegalAgeGroupClassificationlicenseAssignmentStates
mailboxSettingsmailNicknamemySiteonPremisesDistinguishedName
onPremisesDomainNameonPremisesExtensionAttributesonPremisesImmutableIdonPremisesLastSyncDateTime
onPremisesProvisioningErrorsonPremisesSamAccountNameonPremisesSecurityIdentifieronPremisesSyncEnabled
onPremisesUserPrincipalNameotherMailspasswordPoliciespasswordProfile
pastProjectspostalCodepreferredLanguagepreferredName
provisionedPlansproxyAddressesrefreshTokensValidFromDateTimeresponsibilities
schoolsskillssignInSessionsValidFromDateTimestate
streetAddressusageLocationuserType
Table : Microsoft 365 / Azure AD – User object – properties which are returned with only $select
  • Calling the /me endpoint requires a signed-in user and therefore a delegated permission
  • Application permissions are not supported when using the /me endpoint

To get aboutMe property we need to must use $select. This property value returned only on $select

  • Method : GET
https://graph.microsoft.com/v1.0/me?$select=aboutMe

fig : Microsoft Graph - Graph Explorer - Graph API for getting about me property of current user - returned only on $select
fig : Microsoft Graph – Graph Explorer – Graph API for getting about me property of current user – returned only on $select

Get photo

  • We can set profile photos on user accounts, groups and contacts
  • We can use Microsoft Graph APIs to manage / view / download the profile photos
  • Profile photos are stored as binary data
  • Method : GET

https://graph.microsoft.com/v1.0/me/photo/$value

fig : Microsoft Graph - Graph Explorer - Graph API for getting current signed in user photo
fig : Microsoft Graph – Graph Explorer – Graph API for getting current signed in user photo
  • We can request certain specific sizes of photos using Microsoft Graph API
  • The supported sizes of HD photos are
    • 48×48, 64×64, 96×96, 120×120, 240×240, 360×360, 432×432, 504×504, and 648×648
  • We can get the metadata of the largest available photo or specify a size to get the metadata for that photo size.
  • To get the specific size of photo
https://graph.microsoft.com/v1.0/me/photos/48x48/$value

fig : Microsoft Graph - Graph Explorer - Graph API for getting current signed in user photo with specific size
fig : Microsoft Graph – Graph Explorer – Graph API for getting current signed in user photo with specific size

Get all my planner task

  • Method : GET
https://graph.microsoft.com/v1.0/me/planner/tasks

Get all email messages for given user or from shared mail box

  • Method : GET
https://graph.microsoft.com/v1.0/users/{email | userid | userPrincipalName }/messages

fig : Microsoft Graph - Graph Explorer - Graph API for listing all email messages for the given user or from shared mail box
fig : Microsoft Graph – Graph Explorer – Graph API for listing all email messages for the given user or from shared mail box
fig : Microsoft Graph - Graph Explorer - Graph API for listing all email messages for the given user or from shared mail box
fig : Microsoft Graph – Graph Explorer – Graph API for listing all email messages for the given user or from shared mail box

References:

Thanks for reading !! If its worth at least reading once, kindly please like and share !!! SHARING IS CARING 🙂

Enjoy the beautiful life !! Have a FUN !! HAVE A SAFE LIFE !! TAKE CARE 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: