Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to pull data from Web API into PowerBI using Authorization header

I'm trying to pull data from a web Server in PowerBI. The web server uses Oauth and requires you to first create a bearer token by posting to the Authentication endpoint as shown below:   curl --l...
  • Anonymous's avatar
    Anonymous
    6 years ago

    So I've found the solution and it was due to a PowerBI expecting and requiring a content in the API request. Not sure why this is required by PowerBI but this is the magic step I was missing. Full simplified example below:

     

    let
        accesstoken = "token " & #"API",
        url=Text.Combine({#"URL", "/api/tokens/authenticate"}),    
        Source = Json.Document( Web.Contents(url, [ Headers = [#"Authorization" = accesstoken], Content = Text.ToBinary("grant_type=client_credentials") ]))
    in 
    	Source

    The Content of "grant_type=client_credentials" seems to be required for PowerBI when handling the authentication yourself in the query.