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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Unable to Authenticate Anonymous Access OData Feed/API

Hello, 

 

I am working to integrate PowerBI with a vendor solution/API (Cornerstone) and I have the following code to enter into the Advanced Editor: 

 

let
    client_id = "",
    client_secret = "",
    corporation_host = "",
 
    //do not edit section below
    base_url = "https://" & corporation_host & ".csod.com/services/api",
    token_url = base_url & "/oauth2/token",
    odata_url = base_url & "/x/odata/api/views/",
 
    query = [
        clientId = client_id,
        clientSecret = client_secret,
        grantType = "client_credentials",
        scope="all"
        ],
    oauthRequest = Json.FromValue(query),
    Response = Web.Contents(token_url, [
        Content = oauthRequest,
        Headers=[#"Content-type" = "application/json",#"Accept" = "application/json"], ManualStatusHandling = {400}
        ]
    ),
    Parts = Json.Document(Response),
    authToken = if (Record.HasFields(Parts, {"error", "error_description"})) then
                    error Error.Record(Parts[error], Parts[error_description], Parts)
                else
                    "Bearer " & Parts[access_token],
 
    Source=OData.Feed(odata_url,[#"Authorization" = authToken],null),
    //end of do not edit section
    User_View = Source{[Name="vw_rpt_user",Signature="table"]}[Data]
in
    User_View

 

 

I have the correct client secret, ID and site host name, and I am experiencing the following errors: 

 

1) After loading the code into Power Query using the Advanced Editor I get this errror: 

smbigman_0-1697582068249.png

2) When I try to configure anonymous access from data source settings - I am returned with the error that "we couldn't authneticate with the credentials provided. Please try again" 

smbigman_1-1697582521382.png

 

Am I missing something in my code or did I misconfigure my OAuth client for my data source? I am trying to access a production government instance if that provides any insight in terms of secruity. 

3 REPLIES 3
ImkeF
Community Champion
Community Champion

Sorry, no further ideas here.
But often pulling this kind of data via Power Automate into a blob storage first is a good/better alternative.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
did you debug parts of your code already?
Like for example if a Token is actually returned?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi! I am just now re-visiting this and yes - i was able to test via postman and a token is returned. However, still no luck from the PowerBI side. All of the scopes have been turned on the from the Cornerstone (vendor) portal for my service account and I didn't see anything wrong with the config of my OAuth application - I've seen on this forum somebody that was encountering the same issues, but the solution that worked for them (turning on all scopes) did not do the trick for me, I've tried different queries and still no luck populating into PowerBI

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.