Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Graph API - Update Existing Group

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?

like image 443
Stuart Frankish Avatar asked Sep 06 '25 03:09

Stuart Frankish


2 Answers

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
    });
like image 85
Marc LaFleur Avatar answered Sep 07 '25 20:09

Marc LaFleur


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...
            });
like image 34
Thomas Avatar answered Sep 07 '25 20:09

Thomas