user2083386
user2083386

Reputation: 135

Get list of users under a user using Azure graph API

I am looking to implement a method something like below:

If I pass a manager Id to my method, then it needs to give me the list of users whoever report to that manager.

I could find reference where, if I provide a user Id, it gives me the manager to whom the user reports.

GET https://graph.windows.net/myorganization/users/[email protected]/$links/manager?api-version=1.6

https://learn.microsoft.com/en-us/previous-versions/azure/ad/graph/api/users-operations

But I need vice-versa. Something like, I provide the manager Id and I need the list of users under that manager.

Upvotes: 0

Views: 1600

Answers (1)

Allen Wu
Allen Wu

Reputation: 16438

Install the Microsoft Graph .NET SDK here.

Use Client credentials provider to generate the authProvider.

Code sample:

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithTenantId(tenantID)
    .WithClientSecret(clientSecret)
    .Build();

ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var directReports = await graphClient.Users["{upn or user_object_id}"].DirectReports
    .Request()
    .GetAsync();

Upvotes: 2

Related Questions