16

I'm using the Microsoft.Azure.ActiveDirectory.GraphClient (Version 2.1.0) to write an app for Azure AD user management. I'm able to set the Manager of a user but have no idea how to clear the field.

Unfortunately the sample project provided on GitHub do not contain this function either.

juvchan
  • 6,113
  • 2
  • 22
  • 35
stefboe
  • 533
  • 5
  • 26

3 Answers3

9

I managed to clear the "manager" field using the code below. It is not using the Microsoft.Azure.ActiveDirectory.GraphClient library but gets the job done.

var token = <get your adal token here>
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = 
    new AuthenticationHeaderValue("Bearer", token);

var url = "https://graph.windows.net/<tenant domain>/users/<userid>/$links/manager?api-version=1.6"
var resp = httpClient.DeleteAsync(url).Result;
if (!resp.IsSuccessStatusCode)
{
    // log / throw exception etc.   
}
stefboe
  • 533
  • 5
  • 26
3

You need to perform a DELETE HTTP request to https://graph.microsoft.com/v1.0/users/<user_email>/manager/$ref (make sure to replace the <user_email> in the URL.

A successful call will receive 204 response code and empty string as the response body.

This method is currently missing from the Microsoft Graph API docs but should be added in the future. (see here)

Also you should start using Microsoft Graph (graph.microsoft.com) instead of Azure AD Graph (graph.windows.net) as the latter is becoming obsolete. (See here)

Sergiu Indrie
  • 559
  • 5
  • 12
-2
//Assign and remove user's manager
// User.Manager = newUser as DirectoryObject;
           User.Manager = null;
Lily_user4045
  • 795
  • 4
  • 11
  • 1
    When I try to set the Manager Property of a loaded User (casted to DirectoryObject) to null as you suggest and call target.UpdateAsync() afterwards, the manager is still there when I reload the object. – stefboe Mar 22 '16 at 12:02