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.

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

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.


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.

Solution:

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.

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.

http://sharepointscribblings.blogspot.cz/2017/07/call-any-sharepoint-rest-api-from.html

http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/

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

Total Pageviews