I am trying to add members to the group in Azure Active directory using Graph API's in C# but when I run the code I am getting the below error:
ServiceException: Code: BadRequest
Message: Invalid URL format specified in @odata.bind for members
Below is my code:
[AuthorizeForScopes(Scopes = new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser })]
public async Task<IActionResult> AddMembersToGroup()
{
MSGraphs.GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser });
var group = new MSGraphs.Group
{
AdditionalData = new Dictionary<string, object>()
{
{"members@odata.bind", "[\"https://graph.microsoft.com/v1.0/directoryObjects/c6e5c868-e2bd-46b0-b5f3-c39b5dfe42dc\",\"https://graph.microsoft.com/v1.0/directoryObjects/b2fc878b-a455-4315-b9e1-8594cbad3404\",\"https://graph.microsoft.com/v1.0/directoryObjects/79f06743-3bee-418e-8f4e-b381ebdfafc2\"]"}
}
};
await graphClient.Groups["{29f7e645-8de1-45fc-80a5-e76e0fa51340}"]
.Request()
.UpdateAsync(group);
return Ok();
}
Let me know if I am missing something here.