stefboe
stefboe

Reputation: 553

How to remove a users manager in AzureAD using Microsoft.Azure.ActiveDirectory.GraphClient

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.

Upvotes: 16

Views: 1628

Answers (3)

Sergiu Indrie
Sergiu Indrie

Reputation: 568

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)

Upvotes: 3

stefboe
stefboe

Reputation: 553

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.   
}

Upvotes: 9

Lily_user4045
Lily_user4045

Reputation: 793

//Assign and remove user's manager
// User.Manager = newUser as DirectoryObject;
           User.Manager = null;

Upvotes: -2

Related Questions