Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Building an Admin report using REST API.
I can sucessfully get a new Token and use that to retrieve the Group (Workspace) information and then the Reports for each Workspace. But when I use the list of Report IDs to get pages, I get an Access Forbidden message.
Throwing the call with an embedded report GUID:
https://api.powerbi.com/v1.0/myorg/reports/732a489c-20db-4ac4-8c4a-34c2bf033f81/pages
and a newly retrieved Bearer token into Postman, I get the message that the Token is expired:
() =>
let
//Found in Portal Azure site under App Registration: PBIAdminAPI-Dev
tenant_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxx", //Overview Tab: Directory/Tenant ID
client_id = "xxxxx-xxxx-xxxx-xxxx-xxxx", //Overview Tab: Application/Client ID
client_secret = "xxxxxxxxxxxxxxxxxxxx", //Certificates & secrets Tab: PowerBI secret Value
//POST Request
url = "https://login.microsoftonline.com/"&tenant_id&"/oauth2/v2.0/token",
body = [
grant_type = "client_credentials",
scope = "https://analysis.windows.net/powerbi/api/.default",
client_id = client_id,
client_secret=client_secret
],
//Get token
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
Instead of trying to write this yourself why not just use this connector built by Miguel who now works at Microsoft?
It has got all what you are looking for and more!
With respect to my original post, the call https://api.powerbi.com/v1.0/myorg/reports/"&reportid&"/pages only looks at your personal workspace. If the report you specify does not exist there, you will get the access error.
Your connector works well but interestingly has the same issue as the call.
Working with MS Tech support, we found that the API call:
https://api.powerbi.com/v1.0/myorg/groups/"&groupid&"/reports/"&reportid&"/pages
does return the report pages.
So you have to call it in a table that contains the Workspace id (Group id) and the Report ID and pass those to the function (which needs to be modified to accept two parameters).