Add member
-
- 2 minutes to read
-
Add a member to an Office 365 group or a security group through the members navigation property.
You can add users, organizational contacts, or other groups.
Important
You can only add users to security and Office 365 groups managed through the cloud.
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) |
GroupMember.ReadWrite.All, Group.ReadWrite.All, Directory.ReadWrite.All, Directory.AccessAsUser.All |
Delegated (personal Microsoft account) |
Not supported. |
Application |
GroupMember.ReadWrite.All, Group.ReadWrite.All and Directory.ReadWrite.All |
HTTP request
POST /groups/{id}/members/$ref
Header |
Value |
Authorization |
Bearer {token}. Required. |
Content-type |
application/json. Required. |
Request body
In the request body, supply a JSON representation of a directoryObject, user, group, or organizational contact object to be added.
Response
If successful, this method returns a 204 No Content
response code. It does not return anything in the response body.
Example
Request
The following is an example of the request.
POST https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
Content-type: application/json
Content-length: 30
{
"@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('/groups/{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:@"/groups/{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.Groups["{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.groups("{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
The following is an example of the response.
HTTP/1.1 204 No Content