Forum Discussion
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"
]))
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 SourceHere'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 SourceUse 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
4 Replies
- hackcrrMemorable Member
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 SourceHere'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 SourceUse 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
- JackSelmanHelper 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!
- cdc71Frequent 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- JackSelmanHelper I
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.