I don’t have much experience with Power BI, I’m trying to create a REST API that allows me to access the data from my report through Power BI Desktop.
I’ve already created the application in Azure, provided all necessary permissions, enabled access and ID tokens in authentication, and provided administrator consent, so far so good.
I have the following function to generate the token:
()=>
let
tenant_id="...",
client_id = "...",
client_secret = "...",
scope = "https://analysis.windows.net/powerbi/api/.default",
resource = "https://analysis.windows.net/powerbi/api",
url = "https://login.microsoftonline.com/" & tenant_id & "/oauth2/token",
body = [
grant_type = "client_credentials",
client_id = client_id,
client_secret = client_secret,
scope = scope,
resource = resource
],
GetJson = Json.Document(
Web.Contents(
url, [
Headers = [
#"Accept" = "application/json",
#"Content-Type" = "application/x-www-form-urlencoded"
],
Content = Text.ToBinary(Uri.BuildQueryString(body))
]
)
),
access_token = GetJson[access_token]
in
access_token
It generates a token of approximately 1342 characters.
The problem is when I use this token for a simple group request for example:
let
access_token = GetAccessToken(),
url = "https://api.powerbi.com/v1.0/myorg/groups?$top=100",
GetJson = Json.Document(
Web.Contents(
url, [
Headers = [
#"Authorization" = "Bearer " & access_token
]
]
)
),
table = Table.FromRecords({GetJson})
in
table
The result is a table with @data.count = 0, in other words, no results. If I try to access anything else the result is a message “Expression.Error: Access to the resource is forbidden.”.
However, when logging in on the documentation page (Groups – Get Groups – REST API (Power BI Power BI REST APIs) | Microsoft Learn) through “Try it”, a token of 2614 characters is generated and I can make any query and bring everything I need. Even if I copy this token into Power BI Desktop I also get the same result. I could use it in a fixed way, however it expires and it doesn’t make sense for me to have to go to the documentation page to copy the token every time it expires, or worse, have to tell my client to do this…
Apparently, via login with username and password on the documentation page, many other permissions and rules enter the token so it is larger.
The question is, how do I generate this same token from the documentation in Power BI Desktop? Is this currently possible? Am I doing this wrong?
Anyway, I count on the help of a kind soul, as I’ve been trying to solve this for days.
Thank you in advance!
I have already tried to grant all possible permissions, I tested with several options available in videos and blog posts about this, but the result is always the same either access to the resource is forbidden or @data.count = 0.