Skip to content

Latest commit

 

History

History
214 lines (162 loc) · 8.12 KB

File metadata and controls

214 lines (162 loc) · 8.12 KB
title Add directory role member
description Create a new directory role member.
author DougKirschner
ms.reviewer msodsrbac
ms.localizationpriority medium
ms.subservice entra-directory-management
doc_type apiPageType
ms.date 09/17/2024

Add directory role member

Namespace: microsoft.graph

[!INCLUDE beta-disclaimer]

Note

Microsoft recommends that you use the unified RBAC API instead of this API. The unified RBAC API provides more functionality and flexibility. For more information, see Create unifiedRoleAssignment.

Create a new directory role member.

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.

[!INCLUDE national-cloud-support]

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

[!INCLUDE permissions-table]

[!INCLUDE rbac-directory-role-apis-write]

HTTP request

POST /directoryRoles/{role-id}/members/$ref
POST /directoryRoles/roleTemplateId={roleTemplateId}/members/$ref

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
Content-type application/json. Required.

Request body

In the request body, supply a JSON representation of a directoryObject object.

Response

If successful, this method returns a 201 Created response code and a directoryObject object in the response body.

Examples

Example 1: Assign a built-in role to a user

Request

The following example assigns a built-in role to a user.

POST https://graph.microsoft.com/beta/directoryRoles/0afed502-2456-4fd4-988e-3c21924c28a7/members/$ref
Content-type: application/json

{
    "@odata.id":"https://graph.microsoft.com/beta/users/0f933635-5b77-4cf4-a577-f78a5eb090a2"
}

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

HTTP/1.1 204 No content

Example 2: Assign a built-in role to a group

Request

You can use a specific resource set like users or groups in the request body, or you can use generic directoryObjects. This example shows how you can use directoryObjects.

POST https://graph.microsoft.com/beta/directoryRoles/0afed502-2456-4fd4-988e-3c21924c28a7/members/$ref
Content-type: application/json

{
    "@odata.id":"https://graph.microsoft.com/beta/directoryObjects/2c891f12-928d-4da2-8d83-7d2434a0d8dc"
}

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

HTTP/1.1 204 No content

Example 3: Add a new member to a directory role using roleTemplateId

Request

In this request, replace 88d8e3e3-8f55-4a1e-953a-9b9898b8876b with the value of the roleTemplateId for the directory role you wish to assign to the user or directory object. Replace bb165b45-151c-4cf6-9911-cd7188912848 with the id value of your user or directory object.

POST https://graph.microsoft.com/beta/directoryRoles/roleTemplateId=88d8e3e3-8f55-4a1e-953a-9b9898b8876b/members/$ref
Content-type: application/json

{
    "@odata.id": "https://graph.microsoft.com/beta/directoryObjects/bb165b45-151c-4cf6-9911-cd7188912848"
}

Response

HTTP/1.1 204 No content