Forum Discussion

JackSelman's avatar
JackSelman
Helper I
2 years ago
Solved

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...
  • hackcrr's avatar
    2 years ago

    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