Most of the time, when you leave carte blanche to users (aka text fields), it’s almost certain that you’ll get typos, duplicates, and for today’s post… special characters! That’s when the encodeUriCompnent() function may come handy 🙂
It’s not necessary everywhere but, if you’re using the HTTP request actions, then read on!
Backend data
Let’s imagine that we have a SharePoint list, where users have been enjoying freedom and the Title values (text) have been filled as follows.

As we can see, we have many special characters, and will cause issues when trying to retrieve those values when using the HTTP request to SharePoint action with a filter query.
Power Automate
In Power Automate, we’ll use 2 different actions to show where the function is necessary (both with filter queries):
- Get items
- HTTP Request to SharePoint

_api/web/lists/GetByTitle('EncodeUri')/items?$select=Title&$filter=Title eq '@{triggerBody()?['text']}'
For our first test, we’ll use the Contoso & Co Ltd value. And observing the results, we’ll see that the Title is not correct.

While the Get Items actions had no problem, the HTTP request action doesn’t like the “&” because it stops at “Contoso” in the query.

If it works nicely, why not use the Get Items action then? One of the reason is that the HTTP request action gives you some outputs straight away, that you wouldn’t get with the Get Items action.
Now, while the first try is clearly showing there’s an issue, this might not be the case for all special characters, and you may get false positives! Let’s try with another value from the list: SharePoint + Dataverse.
Looks like the flow ran successfully… The Get Items action return the correct item, BUT…

The output query looked like this:
{"dataset":"https://<TENANT-NAME>.sharepoint.com/sites/BlogDemo","parameters/method":"GET","parameters/uri":"_api/web/lists/GetByTitle('EncodeUri')/items?$select=Title&$filter=Title eq 'SharePoint + Dataverse'"}
We’ve got no results with the HTTP request 🤨
encodeUriComponent()
So let’s use our function and try again!
encodeUriComponent(triggerBody()?['text'])

Contoso & Co Ltd results 🥳

SharePoint + Dataverse results 🥳

Hope it helps. Thanks for reading! 🙂