How to get all users with a specific manager with Graph Client Factory?

Nicolas Duchaine 20 Reputation points
2023-04-04T17:48:37.8466667+00:00

Hi, I'm currently developing an SPFx webapp to fetch all users with a specific userPrincipalName as their manager. However, this is my first time working with GraphAPI, and I feel like my query is a bit wobbly, and I need some help. I feel like something is missing in my query, but I'm not quite sure what it is. Thank you!

this.props.context.msGraphClientFactory
      .getClient('3')
      .then((client: MSGraphClientV3) => {
        // From https://github.com/microsoftgraph/msgraph-sdk-javascript sample
        client
          .api("users")
          .version("v1.0")
          .select("displayName,mail,userPrincipalName")
          .expand("manager")
          .filter(`manager/userPrincipalName eq '${escape(this.state.searchForManager)}'`)
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,446 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-04-05T07:38:04.21+00:00

    Hi @Anonymous ,

    Thanks for reaching out! As per my understanding you are trying to fetch all the users' details who are reporting to specific manager. For this scenario, there is a direct API available which will give you the all the users who has manager specified in the request URL/endpoint.

    Get the reports for the manager userPrincipalName.

    https://graph.microsoft.com/v1.0/users/{managerUserPrincipalName}/directReports

    Document reference: https://learn.microsoft.com/en-us/graph/api/user-list-directreports?view=graph-rest-1.0&tabs=http

    Hope this helps. If the reply is helpful, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful