Delete A SharePoint Group Using Microsoft Flow/Power Automate

Introduction

 
In this article, we will learn how to delete a SharePoint Group using Microsoft Flow / Power Automate.
 
As there are no actions available to perform group operations in Microsoft Flow / Power Automate using SharePoint Connector, we will use SharePoint REST API to delete a group.
 

Scenario

 
Let's assume you want to delete a SharePoint group which is no longer useful for you in your SharePoint site and you want to leverage the capabilities of Microsoft Flow/Power Automate for this.
 
But, when you searched for the group deletion action in standard SharePoint connector provided by Microsoft you found out that there are no actions available to perform such group operations. So, you decided to go with the old SharePoint REST API approach.
 
In this article we will create a manually triggered flow and use SharePoint REST API to delete a SharePoint Group.
 

Demo

 
Step 1 - Get ID of SharePoint Group
  • Go to your SharePoint site.
  • Go to SharePoint site settings (https://SiteUrl/_layouts/15/settings.aspx).
  • Select Site permissions.
  • Click on a group name you want to delete.
  • You can find the group ID in browser URL at the end.
    1. https://SiteUrl/_layouts/15/people.aspx?MembershipGroupId=<group-id> 
  • Browser URL will be in above format, group ID will be an integer after "MembershipGroupId=" query string parameter.
  • Copy this group ID and note it down as we will use it later whicle working with Microsoft flow.
Step 2 - Create a flow
  • Go to Microsoft Flow
  • Click on Create from left side pane.
  • Click on Instant flow.
  • Give a name to your flow.
  • Select Manually trigger a flow under "Choose how to trigger this flow" setting.
  • Click on Create button to create our flow.
create a flow
 Name the flow
Step 3 - Delete a SharePoint Group
  • Add Send an HTTP request to SharePoint action.
  • Select a SharePoint site from dropdown or manually enter the SharePoint site address.
  • Select the Method as POST.
  • Configure other options as given below:
Uri
  • Provide the Uri for this action in below format:
    1. /_api/web/sitegroups/removebyid('<group-id>'
  • Replace <group-id> with the SharePoint Group ID we noted earlier in Step 1.
Headers
  • We will add below two headers for this action:

    • accept
    • content-type

  • Provide below value for both these headers:
    1. application/json;odata=verbose 
Finally, save the flow. You final flow should look like the below image:

Delete a group
 
Step 4 - Test / Run the Flow
  • Select Test option from upper right corner in flow editor.
  • Select I'll perform the trigger action option.
  • Then click on Test button.
  • Flow will check and make sure your SharePoint connection is working.
  • Then click on Run flow button.
  • It will show a message stating that Your flow run successfully started.
  • Click on Flow Runs Page link to monitor our test flow run.
  • It will take some time to run this flow and then show the Status as Test succeeded.
Run history
  • If you want see the test flow run in detail then click on the latest run and you can see all the details. 
  • Check the Status code (200) of Send an HTTP request to SharePoint action and notice that your SharePoint group has been deleted successfully.
Flow status
 
Note
Make sure the account you are using to create and publish a flow has sufficient permissions to access the SharePoint Group using SharePoint REST APIs. In order to achieve this you have to change the group settings as mentioned below:
  • Grant owner permissions to the account you are using to create and publish a flow. OR
  • Set Who can view the membership of the group in Group settings to Everyone.
Group settings

Summary

 
In this article, we learned how to delete a SharePoint Group using Microsoft Flow / Power Automate. We used SharePoint REST API to delete a SharePoint group.
 
I hope you liked this article. Give your valuable feedback & suggestions in the comments section below and share it with others.