Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
TSantoro99
New Member

Escape Special Characters '[' and ']' in API query

I am attempting to setup an API query with relative paths so that it can be run from Power BI (web, not desktop). Unfortunately, the API I am working with uses '[' and ']' as part of its required parameter filtering. 😓

 

Does anyone know how to escape these characters so that the following bit of code would run and not throw an 'Invalid Identifier' error?

 

 

 

    Source = Json.Document(Web.Contents("https://secure.fleetio.com/api/v1/", 
    [
        Headers=[Authorization="Token token=""XXXXXXXXXX""", #"Account-Token"="XXXXXX"]
        RelativePath="service_entries"
        Query=[
            q[data_gt]="2019-09-01",
            q[s]="date+desc",
            page="" + page        ]    
    ])),

 

 

 

3 REPLIES 3
TSantoro99
New Member

Thank you for the responses. Phil, your layout seemed to work for querying within the desktop version, but unfortunately, it still was throwing an error when trying to setup an auto-refresh from the online PowerBi due to the dynamic nature of the query. (I think that is the wording they used....).

 

I think this will continue to be a brain-teaser for a while. 

 

Thanks for your help!

PhilipTreacy
Super User
Super User

Hi @TSantoro99 

In Power Query you can escape special characters in strings using their Unicode code e.g. LB = "#(005B)", and in a URL entered into a browser you could use %5B and %5D to replace [and ] but I cannot get this to work with Web.Contents.  Any attempt to use special characters, escape sequences or strings gives and error.

So you may have to just rebuild the query to allow for this, like so;

 

let 

    Param1 = "q[data_gt]=2019-09-01",
    Param2 = "&q[s]=date+desc",
    Param3 = "&page=" & page,

    FullRequest = "https://secure.fleetio.com/api/v1/?"&Param1&Param2&Param3,

    HTTPHeader = [RelativePath="service_entries",

                  Headers = [#"Authorization"="Token token=""XXXXXXXXXX""", #"Account-Token"="XXXXXX"]],

    Source = Json.Document(Web.Contents("https://secure.fleetio.com/api/v1/?"&Param1&Param2&Param3, HTTPHeader))

in
    Source

 

Please note that the value for page is not defined in that query.

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


sevenhills
Super User
Super User

Try and see if it works

     You can escape [  with %5B and ] with %5D

       based on https://www.w3schools.com/tags/ref_urlencode.asp     

 

also check the blog, to escape special characters 

https://blog.crossjoin.co.uk/2018/03/05/character-escape-sequences-in-m/

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.