I'm trying to update the description for an existing group in Azure AD, but I'm getting an error message that I'm not sure how to resolve.
public static async Task<bool> UpdateGroup(GraphServiceClient graphClient, Group group)
{
// Update the group.
Group grp = await graphClient.Groups[group.Id].Request().GetAsync();
grp.Description = group.Description;
await graphClient.Groups[group.Id].Request().UpdateAsync(grp);
return true;
}
The above just throws an exception:
Code: BadRequest Message: Operation not supported.
I'm not sure if this is a lack of enabled permissions for the API in Azure or if updating a group genuinely isn't supported? I can Create/Delete groups easily enough, so surely updating an existing group should be just as easy?
Your problem is that you're first populating grp
, changing a single property, and then attempting to PATCH
the entire Group object. So along with your updated description, you're also attempting to PATCH
(and this is where the error comes from) several read-only properties (e.g. id
).
Your code should look like this:
await graphClient
.Groups[group.Id]
.Request()
.UpdateAsync(new Group() {
Description = group.Description
});
Big thanks to @Marc LaFleur above. The package version I am using differs; the code that worked for me is slightly different without the .Request()
and UpdateAsync()
methods.
await _graphServiceClient.Groups[ActiveDirectoryGroupObjectId]
.PatchAsync(new Group()
{
DisplayName = "Updated Name",
Description = "Updated Description"
// Additional properties...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With