If successful, this method returns a 204 No Content response code. It does not return anything in the response body. This method returns a 400 Bad Request response code when the object is already a member of the group. This method returns a 404 Not Found response code when the object being added doesn't exist.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := graphmodels.NewReferenceCreate()
"@odata.id" := "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
requestBody.Set"@odata.id"(&"@odata.id")
graphClient.GroupsById("group-id").Members().$ref().Post(context.Background(), requestBody, nil)
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new ReferenceCreate();
$requestBody->set@odataid('https://graph.microsoft.com/v1.0/directoryObjects/{id}');
$graphServiceClient->groupsById('group-id')->members()->ref()->post($requestBody);
In the request body, supply a JSON representation of the id of the directoryObject, user, or group object you want to add.
Response
The following is an example of the response.
HTTP/1.1 204 No Content
Example 2: Add multiple members to a group in a single request
This example shows how to add multiple members to a group with OData bind support in a PATCH operation. Note that up to 20 members can be added in a single request. The POST operation is not supported. If an error condition exists in the request body, no members are added and the appropriate response code is returned.
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var group = new Group
{
AdditionalData = new Dictionary<string, object>()
{
{"members@odata.bind", "[\"https://graph.microsoft.com/v1.0/directoryObjects/{id}\",\"https://graph.microsoft.com/v1.0/directoryObjects/{id}\",\"https://graph.microsoft.com/v1.0/directoryObjects/{id}\"]"}
}
};
await graphClient.Groups["{group-id}"]
.Request()
.UpdateAsync(group);
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Group group = new Group();
group.additionalDataManager().put("members@odata.bind", new JsonPrimitive("[ \"https://graph.microsoft.com/v1.0/directoryObjects/{id}\", \"https://graph.microsoft.com/v1.0/directoryObjects/{id}\", \"https://graph.microsoft.com/v1.0/directoryObjects/{id}\"]"));
graphClient.groups("{group-id}")
.buildRequest()
.patch(group);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Group();
$additionalData = [
'members@odata.bind' => ['https://graph.microsoft.com/v1.0/directoryObjects/{id}', 'https://graph.microsoft.com/v1.0/directoryObjects/{id}', 'https://graph.microsoft.com/v1.0/directoryObjects/{id}', ],
];
$requestBody->setAdditionalData($additionalData);
$requestResult = $graphServiceClient->groupsById('group-id')->patch($requestBody);