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...

Thursday, March 29, 2018

Microsoft Flow | Outlook 365 | Get Attachment File size

Scenario: This is a very basic end user requirement that you may want to have a condition to check against the File Size of attachment(s) received in your inbox and then accordingly take next actions.

As per this discussion, there is currently no OOB method to get the size of the attachment via Dynamic content nor there is any expression or function to get you the results.

however, Exchange does check/have restrictions set for every company that we can send or receive mail attachments to specified limit at the server level. so Mail has to have a value where the size is mentioned for the attachment. Fortunately that is available in Flow output as well.

Very Simple steps. below is design and output of the flow.

In below output you will see in 'Compose 2' action only the Size is stored. Basically you can complete avoid the 'Compose' Action and keep only 'compose 2' action, but I have just added it to show how the output of a single attachment look like.

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.

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.

Friday, March 16, 2018

Microsoft Flow | SharePoint Online Alerts | Get list of users subscribed to Out of the box SharePoint Alerts

Sceanrio: Get the list of Users subscribed for Out of the box SharePoint Online Alerts per site/subsite.

It has been a long waited requirement from SharePoint users and Admin globally and an ask to Microsoft to provide a way to get a list of all users who have subscribed alerts on lists/libraries or any object in a SharePoint Site or a subsite. After what feels like a lifetime, Microsoft released Rest API methods for SharePoint Alerts and very recently I had to use them to Get and Delete user alerts using REST API call for a project.

Today, I will be showing How to Get the list of All Users subscribed to alerts for a Site or a Subsite and next blog will be to How to Delete alerts for a specific List or a Library using REST API method in Microsoft Flow.


1. You need to get Access Token for the SharePoint site. I have listed to very commonly browsed articles for same in this Article. Same steps in My MS Flow looks like below.

2. Initialize the Variable. The Output generated from REST API is in Array form. so we need to get only the Results body from "/_api/web/alerts?$expand=user" and store it in a Global Array variable. 

3. Now it gets a bit tricky. I am retrieving only "User Email", "User Display Name" (which comes as Title in REST API results and the "List Title" to which the alert is subscribed to.

This is Uncollapsed screenshot, below I will break it up for better understanding.

Here, from the Original Array results of HTTP REST API call, we will store the values in variables.

In "Create HTML Table" I had kept "Include Headers" as "No", but there is a bug I reported to Microsoft HERE.

Final Step is sending mail to yourself with the output of the HTML table created. 

Microsoft Flow | Get Access Denied for REST API SharePoint call

Scenario: Using Microsoft Flow you need to call HTTP Rest API methods and for that it needs Access Token authorization. You get "Access Denied" permissions error.

"Access denied. You do not have permission to perform this action or access this resource"

To Get Access Token for Authorization
There are many articles online regarding this topic and mostly viewed are below one, from where I got most of the knowledge too.

However, while creating my own Flow and trying to get access tokens, I have faced some issues even after following above 2 articles. one of them I have created an article on "Invalid Client Secret" key error.

Another issue I encountered was when working for subsites or O365 group sites. It would just give me "Access denied" permissions in response body even in POSTMAN. it would not work. Below is what I had to do to fix that.

Even if you are Site Collection Administrator, you will get this issue. Even if you have Trusted the APP with below code, you will get the "Access Denied" error.


After spending many hours and almost giving up, I modified the Trust App code to below and Wow! It worked. It worked for a Subsite and for O365 group site.


So, it is chance you can either use the first code or the second code while Trusting the APP. you cannot use both. Either of one should work. You do not need to create a new Trusted APP. for an existing APP also you can re-trust it with other 'AppPermissionRequest' tag and it will take the new one that you enter.

For more details on SharePoint App Permission Scope, please read this Microsoft Article

Saturday, February 24, 2018

Microsoft Flow | HTTP Rest API | Invalid Client Secret error

Issue: You Get "Invalid Client Secret" error even if the same secret key works fine in Postman.

Scenario: You are using HTTP action to call REST API for SharePoint. you successfully get the Access Token however, the same does not work in GET or POST method and errors out with "Invalid Client Secret". Even though the same client secret works perfectly fine in Postman tool.

I have mostly got this error when the Client Secret key has some plus (+) sign or equal (=) sign in the secret. otherwise it does not give me error.


You need to Encode the special characters.

For Example:- This is the Original client secret key. where we have + sign and = sign.


Encode the client secret as below. Replace + by %2B and = by %3D


Now if you run the flow it should work without any errors. 

More Information on special characters

The reserved character "/", for example, if used in the "path" component of a URI, has the special meaning of being a delimiter between path segments. If, according to a given URI scheme, "/" needs to be in a path segment, then the three characters "%2F" or "%2f" must be used in the segment instead of a raw "/".

Reserved characters after percent-encoding

%0A or %0D or %0D%0A
Common characters after percent-encoding (ASCII or UTF-8 based)

Arbitrary character data is sometimes percent-encoded and used in non-URI situations, such as for password obfuscation programs, or other system-specific translation protocols.

Microsoft Flow | Send mail to Multiple recipients from SharePoint Person Or Group field.

Scenario: you have a SharePoint List where a field with 'Person or Group' having multiple entries is selected. you want to send a mail to all the people entered in that field. However, currently that field is not supported in Microsoft Flow.

Steps on How to get multiple Entries from 'Person or Group' field in SharePoint List and send a single mail to them. 

In This example, I have a simple SharePoint List for Training Registration. Where in the Attendees field multiple people can be selected based on the Nominations. So below we have a field 'Attendees' as 'Person or Group' where 'Allow Multiple Selections:' is selected as "Yes"

  1. I am Triggering MS Flow when a new item is created in the Training Registration SPO List. 
  2. Next Step adding 'Get Item' action and fetching the item created via its 'ID'
  3. Next Step adding 'Data operations - Select' action. (this will take only an Array value as input)
    1. as the output of 'Get Item' will be an array, but I need only the attendees from that New Item created, in 'Select' Action 'From' (input for select) will be the 'Attendees' Field. 
    2. Map Key 'Attendees' to Value 'Attendees Email' (as only email can be used to send a mail.)
  4. Next we will use 'Initialize Variable' action. I named it as 'OriginalArrayAttendees'. Type as 'Array' and Value will be the Output from previous 'Select' action, we get only the Attendees Mail address in the array variable. 
  5. Next we will again use 'Initialize Variable' action. I name it as 'FinalStringAttendees'. Type as 'String' and Value as blank at this stage. 

Now we need to put all the Email addresses into a single variable separated by semi-colon (;) 
  1. Next Step -> Add 'Apply to each' where the output of variable 'OriginalArrayAttendees' is entered. 
  2. from that array, we need to concat all the email addresses with a semi-colon, so we add a 'Data operations - Compose' action and in expression enter "concat(item()?['Attendees'],';')". Pls. Note: Attendees in the concate is the 'Map Key' you gave in the above 'Select' action.
  3. Next step, we need to append the values in a single String variable which is 'FinalStringAttendees'. Pls. Note: If you do not see the variable in 'Dynamic Content', select 'Expression' and type " variables('FinalstringArray') " [ without double quotes] 
  4. Finally use 'Set Variable' action to get the concatenated string of all email addresses in variable so that it can be used out of the 'Apply to each' loop. Value of 'FinalStringAttendees' will be Output of 'Compose 2' action where we are appending all the values. 

Final step is send a Mail. using 'Send an email' action of O365 account. In the "TO" field it will be the 'FinalStringAttendees' variable. Rest of the body you can enter the way you want.

Microsoft Flow | How to send Single mail with Multiple SharePoint List Items.

What is achieved in this Flow?

  1. Run the Flow periodically on a schedule or on some other Trigger as per your choice. 
  2. Query a SharePoint List and GetItems (multiple rows)
  3. Create an HTML Table format with specific fields to be sent in a mail. 
  4. If the Output is Empty, Do not send mail, else send mail to specific recipients. 


  1. I am triggering this Flow on 'Recurrence Schedule' Trigger. 
  2. Getting Items from a SPO List only where the column 'Status' eq 'Request Placed' [ So I am doing OData Filter Query and getting only specific rows from a possibly large SPO List ] 
  3. Next step is the 'Data Operations Select' Action. [ This will take input Only from an Array Output ] 
    1. As the 'Get Items' Output is in Array, 'Select' action works great. The output 'Value' from 'Get Items' will be the Input of  'Select'
    2. 'Map' I am entering the headings of the Table and their values from output of previous steps which will be only those items where 'Status' field value is 'Request Placed'
  4. Next step is put the output of  'Select' Action to String, coz HTML Table action will not take an Array value as Input. so we need to use 'Data operations - compose' Action and put the output of 'Select' in Compose action
  5. Next Add 'Create HTML Table' Action -> Output will be from the 'Compose' step. (by default headers are created in HTML table action Advanced options)
  6. Next I am checking a Condition output is blank (this can be done for any step, it was just easy for me to enter the select output), I wanted to send separate emails if blank and if not blank. So instead of "@empty(body('Select'))" it could also be "@empty(body('Compose')) or "@empty(body('Get_Items'))"

After checking the Condition, I am sending different mails when the condition is True and False. If the condition is False, the output from 'Create HTML table' will be sent in body of the Mail. 

Tuesday, November 28, 2017

Get Task ID from Microsoft Planner Task

How to get the Task ID or Plan ID or even Group ID if you are creating a Plan in O365 groups?

I was trying to get this for Microsoft Flow and searched internet, but did not get any clue. Suddenly it clicked me that everything is URL based.

1. you Click on the Plan/Task for which you want to get the Task ID.
2. From the Browser copy entire URL to Notepad

You will see all the ID's in the URL


so in this case the taskID I needed to use in my MS Flows was "bfdr71NIqkqrDdXxrerNTJYAEL81"

I enter just that string and my Flow was accepting the value and working fine. 

Thursday, March 21, 2013

Certificate error for Federated Domains on O365

One of your on-premises Federation Service certificates is expiring. Failure to renew the certificate and update trust properties within 13 days will result in a loss of access to all Office 365 services for all users. Update now

Follow the articles below in that order.

1. - On the On-Prem ADFS server, Resolution 2, only PS Commands
 Add-PSSnapin Microsoft.Adfs.Powershell
 Update-ADFSCertificate -CertificateType: Token-Signing
2. - Run the commands in this article.

Total Pageviews