ディレクトリ ロールのメンバーを追加する Add directory role member
この記事の内容
名前空間: microsoft.graph Namespace: microsoft.graph
この API を使用して、新しいディレクトリ ロールのメンバーを作成します。 Use this API to create a new directory role member.
注意
この API では、 Directoryrole のオブジェクト ID とテンプレート ID の両方を使用できます。 You can use both the object ID and template ID of the directoryRole with this API. 組み込みのロールのテンプレート ID は不変であり、Azure ポータルのロールの説明に表示できます。 The template ID of a built-in role is immutable and can be seen in the role description on the Azure portal. 詳細については、「 ロールテンプレート id 」を参照してください。 For details, see Role template IDs .
アクセス許可 Permissions
この API を呼び出すには、次のいずれかのアクセス許可が必要です。アクセス許可の選択方法などの詳細については、「アクセス許可 」を参照してください。 One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
アクセス許可の種類 Permission type
アクセス許可 (特権の小さいものから大きいものへ) Permissions (from least to most privileged)
委任 (職場または学校のアカウント) Delegated (work or school account)
RoleManagement、Directory.accessasuser.all、およびすべてのディレクトリ RoleManagement.ReadWrite.Directory, Directory.AccessAsUser.All
委任 (個人用 Microsoft アカウント) Delegated (personal Microsoft account)
サポートされていません。 Not supported.
アプリケーション Application
RoleManagement.ReadWrite.Directory RoleManagement.ReadWrite.Directory
HTTP 要求 HTTP request
POST /directoryRoles/{id}/members/$ref
名前 Name
種類 Type
説明 Description
Authorization Authorization
string string
ベアラー {トークン}。必須。 Bearer {token}. Required.
Content-Type Content-Type
string string
application/json. Required. application/json. Required.
要求本文 Request body
要求本文で、追加する directoryObject またはユーザー オブジェクトの JSON 表記を指定します。 In the request body, supply a JSON representation of a directoryObject or user object to be added.
応答 Response
成功した場合、このメソッドは 204 No Content
応答コードを返します。 If successful, this method returns 204 No Content
response code.
例 Examples
例 1: ロール objectId を使用してディレクトリロールに新しいメンバーを追加する Example 1: Add a new member to a directory role using role objectId
要求 Request
POST https://graph.microsoft.com/v1.0/directoryRoles/{role-objectId}/members/$ref
Content-type: application/json
{
"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}"
}
const options = {
authProvider,
};
const client = Client.init(options);
const directoryObject = {
@odata.id: "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}"
};
let res = await client.api('/directoryRoles/{role-objectId}/members/$ref')
.post(directoryObject);
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directoryRoles/{role-objectId}/members/$ref"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphDirectoryObject *directoryObject = [[MSGraphDirectoryObject alloc] init];
NSError *error;
NSData *directoryObjectData = [directoryObject getSerializedDataWithError:&error];
[urlRequest setHTTPBody:directoryObjectData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var directoryObject = new DirectoryObject
{
Id = "{user-id}"
};
await graphClient.DirectoryRoles["{role-objectId}"].Members.References
.Request()
.AddAsync(directoryObject);
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
DirectoryObject directoryObject = new DirectoryObject();
directoryObject.id = "{user-id}";
graphClient.directoryRoles("{role-objectId}").members().references()
.buildRequest()
.post(directoryObject);
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
応答 Response
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。Note: The response object shown here might be shortened for readability.
HTTP/1.1 204 No Content
Content-type: text/plain
例 2: role templateId を使用してディレクトリロールに新しいメンバーを追加する Example 2: Add a new member to a directory role using role templateId
要求 Request
POST https://graph.microsoft.com/v1.0/directoryRoles/roleTemplateId={role-templateId}/members/$ref
Content-type: application/json
{
"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}"
}
const options = {
authProvider,
};
const client = Client.init(options);
const directoryObject = {
@odata.id: "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}"
};
let res = await client.api('/directoryRoles/roleTemplateId={role-templateId}/members/$ref')
.post(directoryObject);
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directoryRoles/roleTemplateId={role-templateId}/members/$ref"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphDirectoryObject *directoryObject = [[MSGraphDirectoryObject alloc] init];
NSError *error;
NSData *directoryObjectData = [directoryObject getSerializedDataWithError:&error];
[urlRequest setHTTPBody:directoryObjectData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var directoryObject = new DirectoryObject
{
Id = "{user-id}"
};
await graphClient.DirectoryRoles["roleTemplateId={role-templateId}"].Members.References
.Request()
.AddAsync(directoryObject);
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
DirectoryObject directoryObject = new DirectoryObject();
directoryObject.id = "{user-id}";
graphClient.directoryRoles("roleTemplateId={role-templateId}").members().references()
.buildRequest()
.post(directoryObject);
SDK をプロジェクトに追加 し、 authprovider インスタンスを作成する方法の詳細については、 sdk のドキュメント を参照してください。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
応答 Response
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。Note: The response object shown here might be shortened for readability.
HTTP/1.1 204 No Content