Showing posts with label rest api. Show all posts
Showing posts with label rest api. Show all posts

Monday, April 9, 2018

Microsoft Flow | SharePoint Online | Delete all Subsites using REST API

Scenario: You want to Delete all the Subsites within a Site Collection. if you are not a Java script/CSom coder or Powershell scriptor this may help you.

Solution: I will show you a simple Microsoft Flow logic to delete the subsites further you can add conditions for specific subsites and or start approval flows as well for the same and perform your actions as per your requirement.

Overall Successfully running Flow 



1. First Step will be to get the Access Token for HTTP Request to run REST API calls. I have written a blog on this. If you need me to write an article on Getting Access Token, please leave it in the comments below. 

2. from the HTTP POST call, we need to store only the Access Token, so using Compose action, enter [ "@outputs('HTTP').body.access_token" ]  (without box brackets)

3. I am initializing a Global Variable as Array to Store the URL of the subsite, which we will need in the last step of Deleting the subsite. 



4. Now you need to again call HTTP method GET for the site collection and obtain all the subsites under it "/_api/web/webs"

5. Set the Global Array variable to have the results of all subsites obtained in array. [ "@outputs('HTTP_2').body.d.results" ]  (without box brackets)

6. Add 'Apply to Each' and insert the global variable (as the input)

7. Add 3rd HTTP action to finally delete the subsites. Use "Delete" as Method. URI will be as an expression item()?['URL']  and without adding any space append ' /_api/web '

Pls. Note:- This will delete the subsites permanently, they will NOT go to 1st stage Recycle Bin or 2nd stage or Recycle Bin.



This is the basic logic of deleting the subsites, you can further customize it as per your requirement if you need to send an approval mail to the owner of the subsite or check if there are nested subsites etc...


Monday, March 19, 2018

Microsoft Flow | SharePoint Online Alerts | Delete multiple user Out of the box Alerts

Scenario: SharePoint Administrators would love to delete User alerts subscribed to a list/library in one go. But unfortunately there is no way in User Interface that is allowed, you have to do it one by one for every user which is not efficient and very time consuming.

In my Previous blog "Get list of Users Subscribed to OOB Alerts", you can get all Alerts which is also not possible via User Interface.

In this blog I will show how to Delete Alerts for a specific List and the task can be achieved in few seconds.

Solution:
Below is how the Overall uncollapsed version of the Flow looks like. I will break it up further.



1. First we need to connect to the site. so HTTP REST API call to get the Alerts .

Compose data operation "Access Token' enter ' "@outputs('HTTP').body.access_token" ' (with double quotes which is in Bold

Compose data operation "Compose" enter ' "@outputs('HTTP_2').body.d.results"  ' (with double quotes which is in Bold


2. I am initializing a global variable and at the same time setting its output to "Compose" results, which will be the body of Alerts REST API from "HTTP 2" step. 

3. Next, adding an 'Apply for each' from the Array results, we will obtain only 'List title' and 'Alert ID' from the results. both are store in Compose action. 
             To get List Title " item()?['Title'] " (enter without the quotes, only text in bold)
             To get Alert ID " item()?['ID'] "  (enter without the quotes, only text in bold)




4. Next we are checking for a specific List from which we want to delete all the OOB Alerts. Add a Condition where 'Output of ListTitle' is equal to the List.

5. Last step of Alert deletion. If condition is met, we run another HTTP REST API method "DELETE". The syntax for delete is " /_api/web/alerts/deletealert('Alert ID') " . So we need to replace the 'Alert ID' with the output of the compose action where Alert ID of the current item is stored. ( Pls. Note: REST API Method call will be "DELETE" )



On a Successful Deletion once the Condition of List Title is met, HTTP Call for Delete Method will look like below.


Total Pageviews