Add directory role member
-
- 2 minutes to read
-
Use this API to create a new directory role member.
Permissions
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.ReadWrite.Directory, Directory.AccessAsUser.All |
Delegated (personal Microsoft account) |
Not supported. |
Application |
RoleManagement.ReadWrite.Directory |
HTTP request
POST /directoryRoles/{id}/members/$ref
Name |
Type |
Description |
Authorization |
string |
Bearer {token}. Required. |
Content-Type |
string |
application/json |
Request body
In the request body, supply a JSON representation of a directoryObject or user object to be added.
Response
If successful, this method returns 204 No Content
response code.
Example
Request
POST https://graph.microsoft.com/v1.0/directoryRoles/{id}/members/$ref
Content-type: application/json
{
"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}
const options = {
authProvider,
};
const client = Client.init(options);
const directoryObject = {
@odata.id: "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
};
let res = await client.api('/directoryRoles/{id}/members/$ref')
.post(directoryObject);
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/{id}/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];
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 = "{id}"
};
await graphClient.DirectoryRoles["{id}"].Members.References
.Request()
.AddAsync(directoryObject);
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 = "{id}";
graphClient.directoryRoles("{id}").members().references()
.buildRequest()
.post(directoryObject);
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 may be truncated for brevity.
HTTP/1.1 204 No Content
Content-type: text/plain