Search code examples
microsoft-graph-apispfx

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


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)}'`)

I tried working around the select, expand, and filter query in my request, but I didn't find anything that worked.


Solution

  • I would use directReports to get the users assigned to the manager with id or user principal name

    GET https://graph.microsoft.com/v1.0/users/{id|upn}/directReports