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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Power BI GET-Methode with token as request header

Hi evereyone

I'm new to power bi and I'm trying an OAuth using the GET method. But it's not the conventional way, I think.

I can show you the issue with swagger. I get a connection, if i dont fill the 'Bearer token'. I have to give a Request Header as shown.

Mulder_0-1657273128582.png

But how to build that in M-Code?

I have read many instructions on the net, maybe all of them, but I can't find a solution.

See my last attempt:

Mulder_1-1657274192916.png

 

Can anyone please help me?

Regards

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Anonymous ,

 

I think you can follow the below step to get access token and get data from API.

 

  1. Get Access token in Power BI Desktop:
() =>

 

let

    body = "client_id=" & #"App ID"

    & "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"

    & "&grant_type=client_credentials",

    Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",

    [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),

    access_token = Data[access_token]

in

    access_token

 

  1. Video: How to get access token and call Rest API by dynamic access token in Power BI Desktop?

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

HI everyone

 

Sorry for delay, I had to take a little Corona break.

The solution works fine now, thanks to all.

 

regards

Mulder

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

HI everyone

 

Sorry for delay, I had to take a little Corona break.

The solution works fine now, thanks to all.

 

regards

Mulder

Anonymous
Not applicable

Hi @Anonymous ,

 

I think you can follow the below step to get access token and get data from API.

 

  1. Get Access token in Power BI Desktop:
() =>

 

let

    body = "client_id=" & #"App ID"

    & "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"

    & "&grant_type=client_credentials",

    Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",

    [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),

    access_token = Data[access_token]

in

    access_token

 

  1. Video: How to get access token and call Rest API by dynamic access token in Power BI Desktop?

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Not very sure on get part. but check if these can help

https://blog.crossjoin.co.uk/2021/08/29/connecting-to-rest-apis-with-oauth2-authentication-in-power-query-power-bi/

https://community.powerbi.com/t5/Power-Query/OAuth2-REST-API-as-data-source/td-p/414748

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

HI amitchandak

PREVIEW
 
I have read everything from Chris Webb, it helps to build the POST-Method to get the token.
 
But it isn't a Bearer Token. i try serval times, but it dont work.
there ist also a solution from Diogenes Santos wiht Bearer Token like this:
 

authToken = "bearer " & token, //Required by documentation.

[Headers=[Authorization=authToken]]

 

It seems like i cant use the Authorization Methode like this.

The same when i try to fill the OAuth Token in swagger, it doesent work.

 

But Thanks fpr reply

Regards

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors