Microsoft Graph API > setting manager property not working

Steven Kang 1 Reputation point
2022-09-26T11:34:46.257+00:00

I am using MS Graph API to update the user's manager using a C# console application. This was working until a few days ago. It no longer seems to work. I am not getting any errors.

As a test, I used PowerShell to set the manager --> "Set-MgUserManagerByRef". This works fine.

Did something change?

Thanks.
sk

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,875 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,402 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 37,871 Reputation points
    2022-09-27T09:40:37.587+00:00

    Hi @Steven Kang

    Nothing seems to have changed, I just used a C# console application to assign managers to employees and it works fine. Refer to my code:

    using Azure.Identity;  
    using Microsoft.Graph;  
      
    var scopes = new[] { "https://graph.microsoft.com/.default" };      
    var tenantId = "tenant id";  
    var clientId = "client id";  
    var clientSecret = "client secret";  
          
    // using Azure.Identity;  
    var options = new TokenCredentialOptions  
    {  
        AuthorityHost = AzureAuthorityHosts.AzurePublicCloud  
    };   
     
    // https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential  
    var clientSecretCredential = new ClientSecretCredential(  
     tenantId, clientId, clientSecret, options);  
      
    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);  
      
    await graphClient.Users["employee id"].Manager.Reference  
     .Request()  
     .PutAsync("manager id");  
    

    Note that you can only assign managers to employees and cannot assign direct reports to managers.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.