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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Art666
Frequent Visitor

PowerBI RestAPI Dynamic Bearer Code not working

Hi,

 

I connected to the PBI Rest API in PowerQuery.

Currently I am using a static Bearer token, which I copy from the PBI Rest API website.

Art666_0-1693316121014.png

 

Copying this static token and pasting in powerbi, allows me to get all the rquired data. It's fine.

 

 

Problem comes when i try to use the dynamically generated token:

1. The token seems to be totaly different than the one from the website (even shorter).

2. Is not working. Error mesage: "Expression.Error: Access to the resource is forbidden".

 

What is your opinion? How can i overcome this?

 

The PQ code for the dynamic token access

() =>
let
url = "https://login.microsoftonline.com/xxxxxx-xxxxxxxx-xxxx-xxxxxxxxx/oauth2/token",
data = Json.Document(Web.Contents(url,
[
Headers = [
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF=8"],
Content = Text.ToBinary("grant_type = client_credentials&client_id=xxxxxxxxx-xxxxx-xxxx-xxxxxxxxxxxxx&client_secret=xx-xx~xxxxxxxxxxxxxxxxxxxxxxxxx&resource=api://xxxxxxx-xxxx-xxxxxx-xxxxxxxxxxxx")
]
)),
access_token = data[access_token]
in
access_token

 

 

 

thank you in advance!

1 REPLY 1
lbendlin
Super User
Super User

Read about the difference between OAUTH and AAD...

 

Also, this:  GitHub - migueesc123/PowerBIRESTAPI: A Microsoft Power BI Data Connector or Power Query Connector fo...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors