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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading