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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Solution Sage
Solution Sage

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

2 REPLIES 2
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
Solution Sage
Solution Sage

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors