You can use both the object ID and template ID of the directoryRole with this API. The template ID of a built-in role is immutable and can be seen in the role description on the Microsoft Entra admin center. For details, see Role template IDs.
If /$ref is not appended to the request and the calling app has permissions to manage the member object, the object will also be deleted from Azure Active Directory (Azure AD); otherwise, a 403 Forbidden error is returned. You can restore specific objects through the Restore deleted items API.
Request headers
Name
Description
Authorization
Bearer {token}. Required.
Request body
Do not supply a request body for this method.
Response
If successful, this method returns a 204 No Content response code. It does not return anything in the response body.
Examples
Example 1: Remove directory role member using role id
Request
In this example, replace f8e85ed8-f66f-4058-b170-3efae8b9c6e5 with the id value of the directory role and bb165b45-151c-4cf6-9911-cd7188912848 with the id value of the user or directory object that you wish to unassign from the directory role.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
await graphClient.DirectoryRoles["{directoryRole-id}"].Members["{directoryObject-id}"].Ref.DeleteAsync();
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc directory-roles members ref delete --directory-role-id {directoryRole-id} --directory-object-id {directoryObject-id}
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$graphServiceClient->directoryRoles()->byDirectoryRoleId('directoryRole-id')->members()->byDirectoryObjectId('directoryObject-id')->ref()->delete()->wait();
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
await graph_client.directory_roles.by_directory_role_id('directoryRole-id').members.by_member_id('directoryObject-id').ref.delete()
Example 2: Remove directory role member using roleTemplateId
Request
The following is an example of the request. Replace 9f06204d-73c1-4d4c-880a-6edb90606fd8 with the value of your roleTemplateId and bb165b45-151c-4cf6-9911-cd7188912848 with the id value of your user of directory object.