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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
JackSelman
Helper I
Helper I

Template Apps with Parameters in Anonymous API

Hey folks

 

I am trying to develop a template app that I can serve to my customers, connecting to our data as an ISV. We have an API that requires anonymous connection, with the bearer token passed into the query via the header (along with a parameters to define customer instance and tenant).

This works fine for the .pbit, and even works when refreshing the report in Service, as "Skip test connection" is available and circumvents the authentication issue.

However when deploying a template app, I just cannot successfully authenticate, I've tried queries with / without RelativePath but that has not helped.

 

Does anyone else have any experince with providng template apps using paramaterized anonymous API calls, or anything else that could help? I'm pulling my hair out here! Here's the code:

 

= Json.Document(Web.Contents(#"API URL", 
[Headers=[#"-tenant"=Tenant, #"-instance"=Instance, #"Ocp-Apim-Subscription-Key"=#"API Key"],
RelativePath="odata/RecordReports?&$filter=isDeleted eq false"
]))

JackSelman_0-1716222522174.png

 

1 ACCEPTED SOLUTION
hackcrr
Super User
Super User

Hi, @JackSelman 

According to the error message provided in your image, your credentials are invalid and you need to make sure you have provided the correct credentials for your API. You need to make sure that you have provided the correct credentials for your API and used the correct M code for the request. Here's an example of how to properly set up the Web.Contents function:

let
    API_URL = "https://my-api.edison365.com/v1/api/",
    Tenant = "your-tenant",
    Instance = "your-instance",
    API_Key = "your-api-key",
    RelativePath = "odata/RecordReports?$filter=isDeleted eq false",
    Source = Json.Document(Web.Contents(
        API_URL, 
        [
            Headers = [
                #"tenant" = Tenant, 
                #"instance" = Instance, 
                #"Ocp-Apim-Subscription-Key" = API_Key
            ],
            RelativePath = RelativePath
        ]
    ))
in
    Source

Here's a complete example with dynamic parameters:

let
    API_URL = "https://my-api.edison365.com/v1/api/",
    Tenant = Text.From(Parameter_Tenant),
    Instance = Text.From(Parameter_Instance),
    API_Key = Text.From(Parameter_API_Key),
    RelativePath = "odata/RecordReports?$filter=isDeleted eq false",
    Source = Json.Document(Web.Contents(
        API_URL, 
        [
            Headers = [
                #"tenant" = Tenant, 
                #"instance" = Instance, 
                #"Ocp-Apim-Subscription-Key" = API_Key
            ],
            RelativePath = RelativePath
        ]
    ))
in
    Source

Use tools like Postman to ensure that your API calls are correctly formatted and the API is responding as expected. If anonymous access continues to fail, consider using a service principal or OAuth for authentication, which might require some changes in how you manage tokens.

 

 

Best Regards,

hackcrr

If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly

View solution in original post

4 REPLIES 4
cdc71
Regular Visitor

Hi JackSelma,

Were you able to solve this?

I'm having exactly the same issue and it is blocking me in using this as a solution for clients.

hackcrr is not providing a solution.


Kindest regards,
Christ

Hey @cdc71, unfortunately I was not able to solve this. I raised a ticket with MS, met with some of their team, and the couldn't suggest anything beyond using different authenication to solve this - no support or workarounds for the situation I've described.

JackSelman
Helper I
Helper I

Thanks @hackcrr! I know the API credentials are correct as it's refreshing successfully in the service, so looks like I'm off to look at other auth methods!

hackcrr
Super User
Super User

Hi, @JackSelman 

According to the error message provided in your image, your credentials are invalid and you need to make sure you have provided the correct credentials for your API. You need to make sure that you have provided the correct credentials for your API and used the correct M code for the request. Here's an example of how to properly set up the Web.Contents function:

let
    API_URL = "https://my-api.edison365.com/v1/api/",
    Tenant = "your-tenant",
    Instance = "your-instance",
    API_Key = "your-api-key",
    RelativePath = "odata/RecordReports?$filter=isDeleted eq false",
    Source = Json.Document(Web.Contents(
        API_URL, 
        [
            Headers = [
                #"tenant" = Tenant, 
                #"instance" = Instance, 
                #"Ocp-Apim-Subscription-Key" = API_Key
            ],
            RelativePath = RelativePath
        ]
    ))
in
    Source

Here's a complete example with dynamic parameters:

let
    API_URL = "https://my-api.edison365.com/v1/api/",
    Tenant = Text.From(Parameter_Tenant),
    Instance = Text.From(Parameter_Instance),
    API_Key = Text.From(Parameter_API_Key),
    RelativePath = "odata/RecordReports?$filter=isDeleted eq false",
    Source = Json.Document(Web.Contents(
        API_URL, 
        [
            Headers = [
                #"tenant" = Tenant, 
                #"instance" = Instance, 
                #"Ocp-Apim-Subscription-Key" = API_Key
            ],
            RelativePath = RelativePath
        ]
    ))
in
    Source

Use tools like Postman to ensure that your API calls are correctly formatted and the API is responding as expected. If anonymous access continues to fail, consider using a service principal or OAuth for authentication, which might require some changes in how you manage tokens.

 

 

Best Regards,

hackcrr

If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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