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
Anonymous
Not applicable

Anonymous access API OAuth2 connection fail in PBI Service

Hi,

 

Data refresh works fine in PBI Desktop but fails in the PBI Service.

My aadToken query:

 

let 
    Source = (TenantId as text, ClientId as text, ClientSecret as text, Resource as text) => 
let 
    aadRequest = [ 
        grant_type = "client_credentials"
        ,client_id = ClientId
        ,client_secret = ClientSecret
        ,resource = Resource
    ], 
    aadContent = Text.ToBinary(Uri.BuildQueryString(aadRequest)), 
    aadTokenRequest = Web.Contents("https://login.microsoftonline.com/", 
        [ 
            Headers = [#"content-type"="application/x-www-form-urlencoded"], 
            Content = aadContent,
            RelativePath=TenantId & "/oauth2/token" 
        ]
    )
    ,aadTokenJSON = Json.Document(aadTokenRequest)
    ,aadToken = aadTokenJSON[access_token] 
in 
    aadToken 
in 
    Source

 

 

 

 

my GetFacilities query:

 

 

 

let 
    Source = (aadToken as text, opcSubscriptionKey as text) => 
    let 
    customersRequest = Web.Contents("https://apis.collabor8.no", 
        [ 
            Headers = [ 
                #"Method"="POST",
                #"Authorization"="Bearer "& aadToken , 
                #"Content-Type"="application/json",
                #"Ocp-Apim-Subscription-Key" = opcSubscriptionKey
            ],
            RelativePath = "/stable/graph",
            Content=Text.ToBinary(
                "{""query"":""query{
                metadata {
                    facilities{
                        name
                        id
                    }
                }
                }""}")
        ] 
    ), 
    #"customers" = Json.Document(customersRequest)
in 
    #"customers"
in 
    Source

 

I call the aadToken inside my data query:

 

let
    Source = aadToken(),
    Custom1 = GetFacilitiesType(Source, "aa03071324654b71166de3cb58d"),
    data = Custom1[data]
in
    data

 

 

It works fine in the PBI Desktop with Anonymous connection, but when I published it to the workspace I got error 404 when I connect to the API anonymously, even though I'm connecting to the root path and already use the relative path.

404error.png

Any help? Thanks!

1 REPLY 1
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could check the Issues forum here:
https://community.powerbi.com/t5/Issues/idb-p/Issues. If it is not there, then you could post it.
And you could try to open a support ticket. It is free if you have a Pro account.

Go to https://support.powerbi.com. Scroll down and click "CREATE SUPPORT TICKET".

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors