Generating Access Token for Power BI REST API in Power BI Desktop

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>()=>
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
</code>
<code>()=> 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 </code>
()=>
    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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật