Usage Of Encode URI In Power Automate

Introduction

In Power Automate, to return a uniform resource identifier (URI) encoded version for a string by replacing URL-unsafe characters with escape characters we can use either encodeUriComponent or uriComponent functions in expressions.

Step 1

Login to the required Power Apps environment using URL make.powerapps.com by providing the user name and password and click on Flows on the left-hand side as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 2

After step 1, click on New Flow and then Instant Flow, and under option Choose how to trigger the flow select Manually trigger a flow and click on Create button as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 3

After step 2, provide the name as Encode Uri for the flow and then select an operation with the name Initialize variable Action as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 4

After Step 3, Initialize variable is used to hold the URL that needs to be encoded, so provide the name as Uri and Type as String and Value as https://venkatasubbaraopolisetty.com/ and click on New Step as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 5

After step 4, select an Action Compose under Choose an operation as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 6

After step 5, under Inputs  click on Expression and type,

encodeUriComponent(variables('Uri'))

Here encodeUriComponent() is the function and variables (‘Uri’) is the variable value which we received from step 4 as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 7

After step 6, click on the Save button and click on Test as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 8

After step 7, click on Manually and Click on Test as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 9

After step 8, click on Run Flow and you could see below the screen and click on Done as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 10

After step 9, input initialize a variable with Uri turned to encoded URI which is encoded version for a string by replacing URL-unsafe characters with escape characters as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 11

After Step 10, we can also use another recommended function uriComponent by Microsoft by providing under compose operation under expression to encode,

uriComponent(variables('Uri'))

which will encode to equivalent encoded version for a string by replacing URL-unsafe characters with escape characters and save and Test (Repeat Steps 8 and 9)and can see same expected result as shown in the below figure.

Usage of Encode Uri in Power Automate

Step 12

After step 11, one can find both Power Automate functions provided the same result as shown in the below figure.

Usage of Encode Uri in Power Automate

Note

  1. Make sure to save and run the flow whenever you try expressions.
  2. MS documentation is found here
  3. As an example my website is taken into consideration to provide a variable in Step 4, you can provide any other value of your choice.

Conclusion

In this way, one can easily generate an encoded version for a string by replacing URL-unsafe characters with escape characters.