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.

Resolution:

You need to Encode the special characters.

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

"r4QenWWBrPvUw4DCiWIYJpVXWrSXL45FO8ABX6OD++4="

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

r4QenWWBrPvUw4DCiWIYJpVXWrSXL45FO8ABX6OD%2B %2B 4%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 "/".


!
#
$
&
'
(
)
*
+
,
/
:
;
=
?
@
[
]
%21
%23
%24
%26
%27
%28
%29
%2A
%2B
%2C
%2F
%3A
%3B
%3D
%3F
%40
%5B
%5D
Reserved characters after percent-encoding
  


newline
space
"
%
-
.
<
>
\
^
_
`
{
|
}
~
%0A or %0D or %0D%0A
%20
%22
%25
%2D
%2E
%3C
%3E
%5C
%5E
%5F
%60
%7B
%7C
%7D
%7E
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. 

Steps

  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. 


Total Pageviews