Forum Discussion

nhch's avatar
nhch
Helper I
2 years ago

PowerBI Template - parametric REST API - anonymous connection issue

Hi guys,

I'm creating a Template report so that users can connect to their data. 
As a source i'm using some parametric rest APIs not managed by me.
Here's a little snippet of my M code (this works):

let
    Source = Json.Document(
        Web.Contents(
            "https://api.test.com/",
            [
                RelativePath= "prefix/" & parameter & "/suffix",
                Headers=[Authorization=parToken],
                Query=[attr1 = "valattr1", attr2 = "100"],
                Timeout = #duration(0, 0, 1, 0)
            ]
        )
    )


When installing the template the user must specify the parameter so that powerquery can make the API calls.
In this example, if the user's parameter is 123 the working API's path is https://api.test.com/prefix/123/suffix.
The issue is that in order to check if the connection works after the user inserts the parameter powerbi check on the static part of the path (https://api.test.com/) but, without the relative part it dosen't works and a 404 exception is thrown. 

 

Do you have any clue on how to avoid this?
Thank you!
Thomas

7 Replies

  • UPDATE: 
    I tried to remove the relative path and it dosn't return 404.
    Having a static path still don't work tho because when trying to connect it skip the attributes which are used for authentication purposes. 
    Any clue?

      • nhch's avatar
        nhch
        Helper I

        In this case the authentication is given by the attribute in the "Header", not in the path, so i can't use the relative path for authentication. 
        Furthermore, I want to specify that the connection in the powerbi happens flowlesly, the issue is when i'm installing the app created by the Template. 
        There is a step in the installation process in wich PowerBi asks the user to populate the parameters, and to insert his token for authentication purpooses (and that's fine), after that it tries to connect to the data sources and, in doing so, it tries just to connect to the static path without using the authentication's token (the parameter).
        The api throws an error and the user can't connect. 

        I hope this clarify the issue!

        Thanks, 
        Thomas

  • Hey nhch ! I've been facing this exact issue myself for a while now. Did you manage to solve this?

  • Hey nhch ! I've been facing this exact issue myself for a while now. Did you manage to solve this?

    • nhch's avatar
      nhch
      Helper I

      Hi my friend, 
      You will not like my answer but at least it will save you from useless development.
      Online the common advice to solve this issue is to develop a custom connector. I've done it. But in order to make it work you need to have access to a PowerBI Gateway installed on the host machine.
      It's almost obvious to say that if you are facing this issue you don't have access to the host machine.
      So the custom connector IS NOT a solution in our case.
      After that i tried proxing in Azure. A pain.
      The only real way i found to do this is to have a PHP Proxy server. 
      This works but you need a server.

      I hope this helps!

      • JackSelman's avatar
        JackSelman
        Helper I

        Hey nhch, thanks for the update. I appreciate the guidance - as you say, not the solution I was hoping for but at least you've said me some more painful and fruitless testing time!