简体   繁体   中英

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?

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 (eg id ).

Your code should look like this:

await graphClient
    .Groups[group.Id]
    .Request()
    .UpdateAsync(new Group() {
        Description = group.Description
    });

The update operation for group is supported in Graph API. 在此处输入图片说明

I don't have VS env in personal PC, so I cannot test the Graph Library now(I can test it on Oct 2th). If Graph Libray have supported the API too, the code should works well, so you can check your permission config first.

await graphClient.Groups[group.Id].Request().UpdateAsync(grp);

Some reference from Graph Library code:

 /// <summary> /// Updates the specified Group using PATCH. /// </summary> /// <param name="groupToUpdate">The Group to update.</param> /// <returns>The updated Group.</returns> public System.Threading.Tasks.Task<Group> UpdateAsync(Group groupToUpdate) { } /// <summary> /// Updates the specified Group using PATCH. /// </summary> /// <param name="groupToUpdate">The Group to update.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>The updated Group.</returns> public async System.Threading.Tasks.Task<Group> UpdateAsync(Group groupToUpdate, CancellationToken cancellationToken) { }

https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/f807196101e20d30fbc8628206a2eb5850334a92/src/Microsoft.Graph/Requests/Generated/GroupRequest.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM